Results 1 to 5 of 5

Thread: resize to content of a QTreeWidget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    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: resize to content of a QTreeWidget

    There is no natural size for a tree view. A QTreeView is a QAbstractScrollArea. If the content, i.e. the table cells, grow larger than the area available to display it, dictated by the containing layout, then the scroll area gains scroll bars. If you force the horizontal scroll bars to stay hidden then you will have no way to access data outside the current view port. Under no circumstance will the table view automatically resize itself; its sizeHint() is not derived from its content.

    If you want a column to automatically occupy all the remaining space within the current view port then you want to set the section's resize mode QHeaderView::setResizeMode() to QHeaderView::Stretch. If you want the column to always match the content within it then set the resize mode to QHeaderView::ResizeToContents. The QTreeView::setWordWrap() function may also be of use to make longer items viewable. None of these options changes the size of the QTreeView.

    If you really want to resize tree view based on its content then you will need to code to calculate the "correct" size and force it. Set all the sections to QHeaderView::ResizeToContents and query them for their size after every data update to get a reasonable starting point. No matter how much sense it makes you eventually hit the point where the content is too wide for the screen and you are back to where you started.
    Last edited by ChrisW67; 23rd April 2013 at 04:42.

  2. The following user says thank you to ChrisW67 for this useful post:

    torres (29th April 2013)

Similar Threads

  1. How can QTreeWidget force window to resize.
    By Malutek in forum Newbie
    Replies: 2
    Last Post: 4th May 2012, 08:36
  2. Replies: 6
    Last Post: 20th May 2011, 17:56
  3. QTreeWidget not updating content...
    By lni in forum Qt Programming
    Replies: 7
    Last Post: 14th August 2010, 16:06
  4. Resize Row Hieght in QTreeWidget
    By photo_tom in forum Qt Programming
    Replies: 0
    Last Post: 24th May 2010, 15:42
  5. Resize QTreeWidget columns to contents
    By FaS in forum Qt Programming
    Replies: 9
    Last Post: 2nd July 2006, 20:48

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.