[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:


    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(); 

    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

  • Qt Champions 2017

    Hi and welcome
    Have a look at
    QAbstractScrollArea::setHorizontalScrollBarPolicy( )

    and the Qt::ScrollBarAlwaysOff value

  • @mrjj scrollbars already disabled in Qt Designer. Problem actually in extra space, which causes incorrect size computing.

  • Qt Champions 2017

    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();

  • @mrjj thank you, the problem is solved

  • Qt Champions 2017

    you're welcome.
    Very good with the mini sample !

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.