Results 1 to 2 of 2

Thread: QTextDocument update size

  1. #1
    Join Date
    Jul 2015
    Posts
    20
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default QTextDocument update size

    How to update the size of QTextEdit's document?

    i have such function:
    Qt Code:
    1. void QTextEditExtended::setHeightByDoc()
    2. {
    3. int iHeight = this->document()->size().height();
    4. this->setMinimumHeight(iHeight);
    5. this->setMaximumHeight(iHeight);
    6. }
    To copy to clipboard, switch view to plain text mode 

    It's supposed to adjust widget size to text size.
    It works fine on signal textChanged, but doesn't work after inserting text by code (height is always 21).

    Simple example:
    Qt Code:
    1. pText->insertPlainText("blablablabla\r\n");
    2. pText->insertPlainText("blablablabla\r\n");
    3. pText->insertPlainText("blablablabla\r\n");
    4. pText->insertPlainText("blablablabla");
    5.  
    6. pText->setHeightByDoc();
    To copy to clipboard, switch view to plain text mode 

    The height of pText widget will be 21. However, if i activate textChanged signal by e.g. adding a space into my TextEdit, everything works fine and height is set properly. So, my question is how to update document's size after inserting text by code?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTextDocument update size

    Adjust your widget every time the document signals you its contentChanged().

    Also ask yourself what happens when the document height is greater than the screen height. The text edit has scroll bars for a reason.

Similar Threads

  1. Window size problem after Qt version update
    By Krachs in forum Qt Programming
    Replies: 5
    Last Post: 20th November 2014, 19:53
  2. Replies: 3
    Last Post: 10th March 2010, 16:07
  3. QLayout update size signal
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 6th June 2008, 11:24
  4. update window size
    By eric in forum Newbie
    Replies: 3
    Last Post: 14th January 2008, 10:21
  5. QTextDocument printing - specify font size?
    By Scorp1us in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2007, 15:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.