[SOLVED] Creating editor without scrolling
I want to create editor, which will change it's size for content (without scroll). I take QPlainTextEdit, and make next connection:
connect(ui->plainTextEdit->document()->documentLayout(), SIGNAL(documentSizeChanged(QSizeF)), SLOT(editorSizeChanged(QSizeF)));
And in slot I take received height, and multiply it to pixels height of one line:
QFont font("", 0); QFontMetrics fm(font); int pixelsHigh = fm.lineSpacing(); ui->plainTextEdit->setFixedHeight((inSize.height()+1)*pixelsHigh);
This construction works perfectly until we have < 5 lines in editor. After that in the bottom of the editor appears extra space, and scrollbar at right.
What i'm doing wrong ?
Hi and welcome
Have a look at
and the Qt::ScrollBarAlwaysOff value
@mrjj scrollbars already disabled in Qt Designer. Problem actually in extra space, which causes incorrect size computing.
I think your issue is that you use another font for getting line height than the actual editor and
since you multiply then slowly the space grows.
void MainWindow::editorSizeChanged(QSizeF inSize)
@mrjj thank you, the problem is solved
Very good with the mini sample !