Results 1 to 4 of 4

Thread: QTreeWidget Hide Column Headers

  1. #1
    Join Date
    Dec 2016
    Posts
    37
    Qt products
    Qt5
    Platforms
    Windows

    Default QTreeWidget Hide Column Headers

    Hello.

    I've got a QTreeWidget with column headers. When I scroll down to see more data, eventually the column header disappear and I don't know what each column stands for.

    How do I lock the top row so the column headers are always visible?

    Thanks.

    t

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTreeWidget Hide Column Headers

    QTreeWidget's column headers don't scroll, they are always visible. Not sure how you was set it up. My guess is that QTreeWidget is in a QScrollArea.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Dec 2016
    Posts
    37
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTreeWidget Hide Column Headers

    Thank you for your reply.

    Why would having it in a scroll area create this problem? I will have other items below this table so I may need a scroll area.

    n

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTreeWidget Hide Column Headers

    Why would having it in a scroll area create this problem?
    I think you are confusing the scroll bars of a scroll area that contains a tree widget vs. the scroll bars of a standalone tree widget. A scroll area will scroll everything inside it without respect what that is, so if you have a tree widget which reports its height as being greater than the height of the scroll area, then as you scroll down using the scroll area's scroll bar eventually the column headers will scroll out of view. Remember that the scroll area will set its vertical scroll bar to match the height reported by the widget inside it, so if you have a very tall tree, the tree will report its height, the scroll area will say OK, you got it and set its vertical scroll bar appropriately. Because the tree widget thinks it has as much height as it needs, it doesn't turn its scroll bar on. The scroll bar you see belongs to the scroll area, not the tree widget.

    On the other hand, if the tree widget is standalone (eg. in a layout that controls its maximum size), then it will turn on its own scroll bars if the contents are larger than the available space. And when you scroll a tree widget using its own scroll bars, the column headers don't scroll up when you move the vertical scroll bar and will scroll left and right when you move the horizontal scroll bar.

    So you can't have it both ways. You can't put a tree widget inside a scroll area and prevent it from being scrolled off the top if the size of everything in the scroll area is larger than the physical window in which the scroll area lives. That's the way scroll areas work. If you really need the behavior you describe, then a simple scroll area as the main widget in a window won't do it. Probably what you will need to do is make a plain QWidget as the main widget, add a vertical layout to that, then put the tree widget at the top of the layout and add a scroll area under that. That way the tree and the scroll area will have independent scroll bars. You can scroll the contents of the scroll area without affecting the tree.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 0
    Last Post: 9th March 2015, 23:09
  2. QTableWidget do not hide headers on resize, what to do?
    By Bong.Da.City in forum Qt Programming
    Replies: 7
    Last Post: 24th June 2012, 17:39
  3. Replies: 3
    Last Post: 9th May 2011, 18:23
  4. QTableView column-headers too short ...
    By kerim in forum Newbie
    Replies: 2
    Last Post: 20th April 2011, 10:09
  5. QTableView + column span of headers
    By NoRulez in forum Qt Programming
    Replies: 2
    Last Post: 11th November 2009, 15:29

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.