PDA

View Full Version : Howto: Setup QScrollArea correct? - e.g. scrolling is not working...



Astronomy
1st September 2010, 21:07
Hi,

I've created a scrollArea in a widget and added another widget "pjob" to it,
But it does not scroll automatically as it's described in the Class Reference.
(The Image Viewer example also was not a really help) In the Designer i set: Vertical: ScrollbarAlwaysOn and Horizontal: ScrollBarAsNeeded

Do i have to tell the scrollArea the size of the widget pjob, or does that happen automatically?
Do i need scrollAreaWidgetContents? (It's not in the Qt 4.5 docu ??)

any ideas?
Thanx Astronomy




m_ui->setupUi(this);
Jobs *pjob = new Jobs();

m_ui->scrollArea->setWidget(pjob);
m_ui->scrollArea->setWidgetResizable(true);

ChrisW67
2nd September 2010, 04:38
The scroll area will take advice from the internal widget size hint. This is driven by the layout and content of the internal widget. Have a read of the detailed description section in the QScrollArea docs regarding Size Hints and Layouts and try playing with the layout's size constraint.

Astronomy
2nd September 2010, 09:18
OK Thank you,
1st i thougt it might work automatically.. :rolleyes:
but i'll dig in :)

greetz Astronomy

wysota
2nd September 2010, 12:57
OK Thank you,
1st i thougt it might work automatically.. :rolleyes:
It does but you didn't set a layout for the contents of the scroll area so it has no way of knowing how it should manage its own space.

Astronomy
17th September 2010, 13:02
Hello again,

today i had the time to solve this problem with your suggestions :)
At: http://doc.trolltech.com/latest/qscrollarea.html#setWidget
is the hint:
Note that You must add the layout of widget before you call this function; if you add it later, the widget will not be visible - regardless of when you show() the scroll area. In this case, you can also not show() the widget later.

With QLayout i had some problems, but at last:

I had to set the minimum size of my custom widget, before i add it to the scrollArea.
So everytime i change the size of pJob because of adding new functionyllity -eg widgets to it scrollArea will adapt automatically.

i did at my constructor:



...
m_ui->setupUi(this);
Jobs *pjob = new Jobs();

QSize AdjustSize = pjob->size();
AdjustSize.width(); // for debugging...

// Adjust scrollArea to this size,
pjob->setMinimumSize(AdjustSize); // Advantage: everytime you change the size of pJob,
// because of adding new functionyllity -eg widgets to it..
// scrollArea will adapt automatically (-:

m_ui->scrollArea->setWidgetResizable(true);
m_ui->scrollArea->setWidget(pjob);



Thank you very much,
& have a nice day
Astronomy

yungyeh
27th June 2013, 14:22
Hello again,

today i had the time to solve this problem with your suggestions :)...



Thanks so much. This is the only explicit example I found on line that explain what's going on with scrollarea created with UI not showing properly issue. Solve my doubt and improve my skill. Thanks again.