Qt Scroll Area does not add in scroll bars

前端 未结 2 950
-上瘾入骨i
-上瘾入骨i 2021-01-23 08:36

Hi guys I have to dynamically create push buttons depending on user inputs, therefore if user gives a large input number the widget containing the push buttons has to have the a

相关标签:
2条回答
  • 2021-01-23 09:24

    You need to add your horizontalWidget to a vertical widget like so:

    QVBoxLayout* vLayout = new QVBoxLayout();
    
    for (int i = 0; i < numberOfSlices; i++)
    {
        QWidget *horizontalWidget = new QWidget();
        vLayout->addWidget(horizontalWidget);
        ....
    }
    scrollAreaWidgetContents->setLayout(vLayout);
    

    You second problem looks like it comes from this line:

    scrollArea = new QScrollArea(verticalWidget);
    

    You're adding scrollArea directly to verticalWidget, but to get it to lay out the way you want you need to put it in a layout. Try the following instead:

    QVBoxLayout* l = new QVBoxLayout();
    l->addWidget(sliceLabel); // or whatever you call it
    l->addWidget(scrollArea);
    l->addWidget(clearButton); // again, your name here
    verticalWidget->setLayout(l);
    
    0 讨论(0)
  • 2021-01-23 09:31

    Try playing around with the QScrollBarPolicy.

    http://doc.qt.digia.com/qt/qabstractscrollarea.html#horizontalScrollBarPolicy-prop

    I'm guessing that the default behavior isn't working because there is something strange going on with layouts.

    0 讨论(0)
提交回复
热议问题