PDA

View Full Version : Multiple QTreeViews in a QScrollArea?



MarkSimon
7th April 2010, 22:42
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.

wysota
7th April 2010, 23:06
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.

MarkSimon
8th April 2010, 09:41
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.

wysota
8th April 2010, 15:09
The vertical scrollbar is the one keeping the desired height of the tree.

MarkSimon
9th April 2010, 14:08
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.

wysota
9th April 2010, 21:07
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.

cyberbob
18th November 2010, 05:19
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:


QStandardItemModel *model=new QStandardItemModel();
model->setItem(0, 0, new QStandardItem("item 1"));
model->setItem(0, 1, new QStandardItem("item 2"));
model->setItem(0, 2, new QStandardItem("item 3"));
model->setItem(0, 3, new QStandardItem("item 3"));
model->setItem(0, 4, new QStandardItem("item 3"));
model->setItem(0, 5, new QStandardItem("item 3"));

QWidget *window = new QWidget;
window->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
QScrollArea * area = new QScrollArea(window);
//area->setWidgetResizable(true);
area->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
QHBoxLayout * hBox = new QHBoxLayout(area);
hBox->setSizeConstraint(QLayout::SetNoConstraint);
hBox->setGeometry(QRect(0, 0, 1000, 1000));

QTableView *tableView1 = new QTableView();
tableView1->setModel(model);
hBox->addWidget(tableView1);
tableView1->resize(1000, 1000);
tableView1->setGeometry(0, 0, 1000, 1000);

QTableView *tableView2 = new QTableView();
tableView2->setModel(model);
hBox->addWidget(tableView2);

window->show();

return app.exec();

But here is what I get:

5479

Please advice something?

wysota
20th November 2010, 08:25
So why don't you hide one scroll bar?

cyberbob
20th November 2010, 20:02
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:

5508

wysota
20th November 2010, 20:05
And what is keeping you from doing that?

cyberbob
20th November 2010, 20:14
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?

wysota
20th November 2010, 21:48
Compute the right size and have your tree views return it as their sizeHint.

cyberbob
23rd November 2010, 03:06
That worked, I just thought there is some other proper way for QTableView.
Thanks.