Results 1 to 13 of 13

Thread: Multiple QTreeViews in a QScrollArea?

  1. #1
    Join Date
    Apr 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Multiple QTreeViews in a QScrollArea?

    Hi,
    I'm trying to display several QTreeViews vertically, layed out using a QVBoxLayout onto a QFrame, and then put that QFrame into a QScrollArea. The problem is I can't get the QTreeViews to display at their full height - I don't want the vertical scroll bar as I already have the scroll bar of the main QScrollArea - I want them to take up as much room as they need and expand as items are added, and contract as items are removed.

    I've scoured the Internet for answers and I've tried different size policies for the qtreeviews, the qframe, the qvboxlayout, but I just can't get it to work.

    Any ideas anyone?

    Thanks!

    Mark.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Multiple QTreeViews in a QScrollArea?

    Size policies won't help you with anything here. You have to manually keep track of the size of the viewport and resize your widgets accordingly.

  3. #3
    Join Date
    Apr 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Multiple QTreeViews in a QScrollArea?

    Thanks for your response.
    How would I go about getting the height I would need? I tried qtreeview->viewport()->height(), but that did not give the entire height by a long way. In fact it seemed to be the height currently being viewed instead of the entire height of the tree.

    Thanks,

    Mark.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Multiple QTreeViews in a QScrollArea?

    The vertical scrollbar is the one keeping the desired height of the tree.

  5. #5
    Join Date
    Apr 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Multiple QTreeViews in a QScrollArea?

    Thanks - I did try that (vbar->maximum()) but strangely the value seemed short of what it should be. If I set the minimum height of the tree view that contained 1000's of items to this value, I would still get a scroll bar. It seemed to be a few hundred pixels off.

    For the moment, I'm doing it by multiplying the number of items by the height of each item (i'm using a delegate so I know the heights), which seems to work perfectly.

    I will revisit using the vbar maximum value in case I missed something.

    Many thanks for your help,

    Mark.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Multiple QTreeViews in a QScrollArea?

    The scrollbar will determine the size of the viewport but there is more to the tree than just the viewport. I doubt it explains why your calculations are off by few hundered pixels but it would explain a discrepancy of several pixels.

  7. #7
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Multiple QTreeViews in a QScrollArea?

    I have the same question, with multiple QTableViews inside QScrollArea. I want to have one scroll for set of fully expanded tables, but only get one scroll per table.

    Here is the code:

    Qt Code:
    1. model->setItem(0, 0, new QStandardItem("item 1"));
    2. model->setItem(0, 1, new QStandardItem("item 2"));
    3. model->setItem(0, 2, new QStandardItem("item 3"));
    4. model->setItem(0, 3, new QStandardItem("item 3"));
    5. model->setItem(0, 4, new QStandardItem("item 3"));
    6. model->setItem(0, 5, new QStandardItem("item 3"));
    7.  
    8. QWidget *window = new QWidget;
    9. window->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    10. QScrollArea * area = new QScrollArea(window);
    11. //area->setWidgetResizable(true);
    12. area->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    13. QHBoxLayout * hBox = new QHBoxLayout(area);
    14. hBox->setSizeConstraint(QLayout::SetNoConstraint);
    15. hBox->setGeometry(QRect(0, 0, 1000, 1000));
    16.  
    17. QTableView *tableView1 = new QTableView();
    18. tableView1->setModel(model);
    19. hBox->addWidget(tableView1);
    20. tableView1->resize(1000, 1000);
    21. tableView1->setGeometry(0, 0, 1000, 1000);
    22.  
    23. QTableView *tableView2 = new QTableView();
    24. tableView2->setModel(model);
    25. hBox->addWidget(tableView2);
    26.  
    27. window->show();
    28.  
    29. return app.exec();
    To copy to clipboard, switch view to plain text mode 

    But here is what I get:

    tables_scroll.png

    Please advice something?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Multiple QTreeViews in a QScrollArea?

    So why don't you hide one scroll bar?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Multiple QTreeViews in a QScrollArea?

    Thanks for the reply. Sorry if I was not specific in details, but I would like to have one scroll bar (from QScrollArea ?) to scroll all the tables.

    Here is the idea:

    multiple-tables.png

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Multiple QTreeViews in a QScrollArea?

    And what is keeping you from doing that?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Multiple QTreeViews in a QScrollArea?

    Tables are resized to fit main window (activating their scroll bars) even if they are in scroll area. Is it possible maximize tables, give them as much space as they need to be without scrolls and then put them into one scroll area?
    Could you give some hint on how my goal can be achieved?

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Multiple QTreeViews in a QScrollArea?

    Compute the right size and have your tree views return it as their sizeHint.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. The following user says thank you to wysota for this useful post:

    cyberbob (23rd November 2010)

  14. #13
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Multiple QTreeViews in a QScrollArea?

    That worked, I just thought there is some other proper way for QTableView.
    Thanks.

Similar Threads

  1. iTunes Artist View-like QTreeViews
    By idadesub in forum Qt Programming
    Replies: 3
    Last Post: 21st March 2008, 12:28
  2. Replies: 2
    Last Post: 10th March 2008, 20:16
  3. QTreeViews should not expand!
    By zwwe in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2008, 14:52
  4. QScrollArea
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 13th December 2007, 17:20
  5. Replies: 0
    Last Post: 21st December 2006, 11: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.