[SOLVED] Creating editor without scrolling
-
Hello!
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 ?
Minimal example -
Hi and welcome
Have a look at
QAbstractScrollArea::setVerticalScrollBarPolicy()
QAbstractScrollArea::setHorizontalScrollBarPolicy( )and the Qt::ScrollBarAlwaysOff value
-
@Yakov-Eremin
hi
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.try with
void MainWindow::editorSizeChanged(QSizeF inSize)
{
QFont font=ui->plainTextEdit->font();
..... -
@Yakov-Eremin
you're welcome.
Very good with the mini sample !