Nominate our 2022 Qt Champions!

QScrollArea nested layouts

  • Hi all,

    I got some problems with the QScrollArea. Following code creates a Qt3DWindow in a windowContainer.
    This container is embedded in a QHBoxLayout along with a QVBoxLayout which contains several other widgets (like buttons).
    For the case that the QVBoxLayout gets stuffed with too many widget I would like to make i scrollable but my approaches were not satisfying.

    original code which works fine (without scrolling):

    QWidget* container = QWidget::createWindowContainer(view); // view => Window3D
    QSize screenSize = view->screen()->size();
    container->setMinimumSize(QSize(200, 100));
    QWidget* widget = new QWidget;
    QHBoxLayout* hLayout = new QHBoxLayout(widget);
    QVBoxLayout* vLayout = new QVBoxLayout;
    hLayout->addWidget(container, 1);

    scolling approach:

    QWidget* widget = new QWidget;
    QHBoxLayout* hLayout = new QHBoxLayout(widget);
    QWidget* widget2 = new QWidget;
    QVBoxLayout* vLayout = new QVBoxLayout(widget2);
    hLayout->addWidget(container, 1);
    QScrollArea* area = new QScrollArea;
    area->setWidget(widget); // whole layout is scrollable
    //area->setWidget(widget2); // only vLayout is displayed (and scrollable)

    This is from the Qt3D example "basicshapes". I want to make the verticalLayout at the right scrollable while the 3D view container stays the same size. The original code from above belongs to this.


Log in to reply