[Interest] Layout on a QScrollArea not properly downsized when changed off-screen

Alejandro Exojo aexojo at modpow.es
Fri Jun 14 12:12:08 CEST 2013


I've implemented a kind of vertical list of widgets with a class based on
QScrollArea. The main widget has QVBoxLayout as layout. I have a method to
clear the whole list and empty the layout, and another to add one widget to
the layout.

The problem I'm having is that I clear and fill the layout both with the
widget visible and not visible (the list is in a QDialog, so I have to fill
it before I call exec()). When the list/layout contents change with the
widget visible, everything is fine. But if I do it before the exec(), so
before is shown, the layout only grows if previously had less items, but it
never shrinks if I empty it and add less items than previously.

I'm doing the following to empty the list, where m_list is a QList with
pointers to the elements added and m_layout is the layout of the widget()
of the QScrollArea:

void List::clear()
    while (!m_list.empty()) {
        QWidget* widget = m_list.takeLast();
        delete widget;

And the following to add widgets:

void List::addWidget(QWidget* item)
    // This widget draws a left-bottom-right frame.
    QWidget* frame = new QWidget(this);
    frame->setStyleSheet(".QWidget {"
        "border: 3px solid rgb(6, 78, 125);"
        "border-top: 0px;"
    // Wrapper layout: the frame widget has inside the interesting contents
(another widget)
    QVBoxLayout* wrap = new QVBoxLayout();
    frame->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);


I've also put the main widget in an event filter, and I've seen is
receiving Resize events when calling addWidget with the widget visible, but
no resize events at all before is shown.

I've also tried to call update() and repaint() in layouts and widgets here
and there, but no change at all.

Any ideas are welcome.

Thanks in advance.

Alejandro Exojo Piqueras

ModpoW, S.L.
Technova LaSalle | Sant Joan de la Salle 42 | 08022 Barcelona |
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130614/7fd9c472/attachment.html>

More information about the Interest mailing list