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
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
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.
Or use QTextDocument and its settings.
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
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.
Bookmarks