PDA

View Full Version : Using QScrollArea



Jimmy2775
2nd March 2006, 20:58
Hi there. I am new to Qt and was hoping to get some advice.

I am trying to create a custom widget that consists of multiple QTableViews, organized using a QVBoxLayout. Since this widget could potentially grow quite large, I would like to be able to specify a size for the control and be able to scroll horizontally/vertically as required to view the QTableViews.

I am encountering some difficulties implementing this, however, and am getting a little frustrated with the lack of information available regarding Qt4's QScrollArea. If there is any info regarding this topic on the internet, I would appreciate a link to it.

More specifically, I have a few questions about my design and implementation:

Is it better to put the widget in a QScrollArea, or to have the widget inherit from QScrollArea/QAbstractScrollArea
Is there any documentation regarding the use of QSizeHint and QSizePolicy? I have read the official documentation but the use of these is still not clear to me.


Any info is appreciated.

Jimmy

jpn
2nd March 2006, 21:07
Try setting the vbox layout to a widget and setting it to the scroll area. No need to inherit scroll area in this case..

Jimmy2775
2nd March 2006, 21:14
That sounds promising. Could you please be a little more explicit, though? I don't quite follow your meaning here.

Thanks.

jpn
2nd March 2006, 21:17
Something like this:


QWidget* widget = new QWidget;
widget->setLayout(vbox);
scrollarea->setWidget(widget);


The vbox layout contains all tables and so on and is able to count the needed size and works nicely in a scroll area.. Just test and see how perfectly it works ;)

Jimmy2775
2nd March 2006, 21:26
Oh sweet - thanks jpn. Now this is starting to look the way I'd like.

A further question...

I want to set the height of the QTableView to be the height of its contents, but the only way I can see to do this is to loop through all the rows and add each rowHeight. Is there a more efficient way to do this?