Results 1 to 4 of 4

Thread: QTreeWidget won't scroll horizontally

  1. #1
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QTreeWidget won't scroll horizontally

    Hi, this has really been bugging me.

    I have a QTreeWidget in a QVBoxLayout and that layout is set to a QGroupBox. For whatever reason, the treeview doesn't recognize when it needs to scroll horizontally, and if I manually call setHorizontalScrollPolicy(Qt::ScrollBarAlwaysOn); the scroll bar is visible, but there is no bar to scroll. The strangest part is that the vertical scroll works just fine.

    Here is some of my code...I didn't put the code where I populate the treeview as its long and to my mind irrelevant.

    Qt Code:
    1. treeWidget = new QTreeWidget();
    2. treeWidget->setColumnCount(1);
    3.  
    4. verticalLayout = new QVBoxLayout();
    5. verticalLayout->addWidget(treeWidget);
    6.  
    7. groupBox->setLayout(verticalLayout);
    To copy to clipboard, switch view to plain text mode 

    I've tried populating the treeview both before its set to the layout and after. No change.

    Does anyone have any ideas? Seems like it should work...

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeWidget won't scroll horizontally

    You would have to turn the stretching off:
    Qt Code:
    1. treeWidget->header()->setStretchLastSection(false);
    To copy to clipboard, switch view to plain text mode 
    Notice that QHeaderView provides several methods for handling section resizing.
    J-P Nurmi

  3. #3
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTreeWidget won't scroll horizontally

    Thanks alot. I didn't see your post and finally got it to work by calling treeWidget->resizeColumnToContents(0) each time a node was expanded. Your method seems much cleaner.

  4. #4
    Join Date
    Jan 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget won't scroll horizontally

    Thanks, even I was facing this problem.

    in addition, I had to write following line

    Qt Code:
    1. header()->setResizeMode(QHeaderView::ResizeToContents);
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 23rd January 2008 at 08:56. Reason: missing [code] tags

Similar Threads

  1. ListWidget horizontal scroll.
    By patrick772goh in forum Qt Tools
    Replies: 3
    Last Post: 17th July 2007, 07:32
  2. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32
  3. QScrollArea's Scroll Bars
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 19th September 2006, 13:27

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.