Results 1 to 5 of 5

Thread: QTextEdit 80 chars wide

  1. #1
    Join Date
    Apr 2009
    Posts
    32
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTextEdit 80 chars wide

    Hi,

    Suppose I have a QTextEdit set up with a monospace font. How do I make the text edit field exactly 80 chars wide? E.g. similar to a command prompt window.

    Best regards,

    Mads

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit 80 chars wide

    You can use QFontInfo to calculate the pixel width of an 80 chars long string, and set that width to the QTextEdit.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QTextEdit 80 chars wide

    Or use QTextDocument and its settings.

  4. #4
    Join Date
    Apr 2009
    Posts
    32
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit 80 chars wide

    Yes, I tried to do that and put it into the return value from the sizeHint() method. But the window is still to narrow to fit the 80 chars (2 chars short). There's probably more properties that I have to include in the calculation of the total QTextEdit width, but I'm uncertain about all the things that should be included (margins, frames, etc).

    Any help is appreciated.

    Mads

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit 80 chars wide

    You need the text edit's viewport to be of this size and not the whole widget. Consider that the text edit also has scrollbars and a frame around the viewport.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Getting system wide X11 events problems
    By wandereq in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2010, 20:13
  2. QTreeWidget Items display too wide.
    By chris_helloworld in forum Qt Programming
    Replies: 2
    Last Post: 26th February 2010, 13:36
  3. Static casting of signed chars
    By ShamusVW in forum Qt Programming
    Replies: 0
    Last Post: 4th November 2009, 05:46
  4. qgetenv and special chars
    By miraks in forum Qt Programming
    Replies: 6
    Last Post: 21st March 2009, 13:48
  5. Need help. can't append chars in QString
    By AcerExtensa in forum Qt Programming
    Replies: 6
    Last Post: 12th June 2008, 10:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.