Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set number of lines for an QTextEdit?

I use a QTextEdit for some inputs. But I want to adjust the height of the box. Can I set the height based on the number of lines I want to have visible at a time?

like image 804
Mnementh Avatar asked Mar 10 '11 10:03

Mnementh


People also ask

How to set size of QTextEdit?

Re: Resizeable QTextEdit within a layout Just stick the text edit in a layout and on resize (grab and drag) change its fixed size.

How do I get text from QPlainTextEdit?

The entire text can be selected using selectAll(). QPlainTextEdit holds a QTextDocument object which can be retrieved using the document() method. You can also set your own document object using setDocument().


1 Answers

If you use QPlainTextEdit, something like this should do the trick:

void SetHeight (QPlainTextEdit* edit, int nRows)
  {
  QFontMetrics m (edit -> font()) ;
  int RowHeight = m.lineSpacing() ;
  edit -> setFixedHeight  (nRows * RowHeight) ;
  }

You might want to add two or three pixels as margin; experiment will tell.

like image 77
TonyK Avatar answered Oct 17 '22 10:10

TonyK