PDA

View Full Version : QTextEdit 80 chars wide



mpi
27th January 2011, 09:52
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

high_flyer
27th January 2011, 10:02
You can use QFontInfo to calculate the pixel width of an 80 chars long string, and set that width to the QTextEdit.

tbscope
27th January 2011, 10:07
Or use QTextDocument and its settings.

mpi
27th January 2011, 10:30
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

wysota
29th January 2011, 13:18
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.