Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextEdit resizing
Forum Updated to NodeBB v4.3 + New Features

QTextEdit resizing

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 252 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    olexayko
    wrote on last edited by
    #1

    How do i make textedit field occupy as much place as much text occupies?
    dec19660-fc08-4be2-9f3b-e67a8c1876e6-image.png

    When text bounds is bigger than textedit, scrollbar appears, but i want it to resize to fit whole text without vertical scrollbar appearing instead. i implemented such a crutch:

    ui->textEdit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
        if (ui->textEdit->verticalScrollBar()->isHidden())
        {
            qDebug() << "no scrollbar";
        }
        else
        {
            while(ui->textEdit->verticalScrollBar()->isVisible())
            {
                ui->textEdit->setFixedHeight(ui->textEdit->height() + 1);
            }
        }
    

    but it doesnt help, when text block is smaller than actual size of QTextEdit; also, when I perform this function on QTextEdit placed into vertical layout, it begins overlap other widgets, no matter I call after verticalLayout update() and invalidate() methods.
    080f916e-a227-4878-ac59-83b46cd17d68-image.png
    I have played a lot with sizePolicy, still no result. Looking for an advice, if someone can provide minimal running example, it would be great.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      One thing you can do is get the size of the underlying QTextDocument and modify the size of your QTextEdit accordingly.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved