Scroll Bars Missing from QScrollArea



  • I know this has been touched on in other posts, but those don't appear to be related to my setup, at least as I understand it.

    So here is the code first of all. I'm using a for loop to generate a bunch of scroll areas and widgets and place them in a QStackedWidget. Then I'm assigning these widgets as parents to the widgets I want to display (would be nice if I could just assign them directly to the scrollarea, not sure if that's possible).

    for(int index=0; index <12; index++ )
        {
            QScrollArea *scroll = new QScrollArea();
            QGridLayout *grid = new QGridLayout();
            QWidget *widget = new QWidget();
            m_mainWidgets.append(widget);
            widget->setLayout(grid);
            scroll->setWidget(widget);
            scroll->setWidgetResizable(true);
            ui->mainStackedWidget->addWidget(scroll);
        }
    
        ui->mainStackedWidget->setCurrentIndex(0);
    
        m_pManTabWidget = new ManTabWidget(m_client,m_mainWidgets[0]);
        m_pMotionTestPage = new MotionTestWidget(m_client,m_mainWidgets[1]);
        m_pMotionPage = new MotionPage(m_client,m_mainWidgets[2]);
    

    There are more widgets, but it's more of the same code, and that part works.
    The stacked widgets display correctly and the buttons I have mapped to them work as intended, all good. No issues there. However, there are no scroll bars even though the widgets are clearly occluded on the right hand side, as in this example. All appear like this. It's as if the scroll area just expands behind where you can see and thus doesn't bother placing scroll bars.
    0_1519741985395_Capture.PNG

    I've tried setting

    scroll->setWidgetResizable(true);
    

    to false, or removing this, and all it does is cause everything within the stacked widget to stop being displayed.

    I've tried it without the grid layout and with the grid layout. This doesn't appear to change anything.


  • Moderators

    @graniteDev
    when you add widgets to the grid-layout it will work.
    Currently it seems you just add some widgets to scrollarea's widget "directly" (without a layout).
    This means the scrollarea's content widget gets resized, but doesn't propagate the size changes. Also most important (at least the snipped you've posted) the QGridLayout grid doesn't get any widget added. Thus there is no sizeHint for the content widget which is essential for the scrollbar calculation.



  • You are overcomplicating things:

    for(int index=0; index <12; index++ )
        {
            QScrollArea *scroll = new QScrollArea();
            m_mainWidgets.append(scroll );
            scroll->setWidgetResizable(true);
            ui->mainStackedWidget->addWidget(scroll);
        }
    
        ui->mainStackedWidget->setCurrentIndex(0);
    
        m_mainWidgets[0]->setWidget(m_pManTabWidget = new ManTabWidget(m_client));
        m_mainWidgets[1]->setWidget(m_pMotionTestPage = new MotionTestWidget(m_client));
        m_mainWidgets[2]->setWidget(m_pMotionPage = new MotionPage(m_client));
    


  • @VRonin haha, inexperience is the mother of all overcomplication. Thank you for the simplification. I did this and it worked perfectly. Scroll bars are now present and accounted for!

        for(int index=0; index <12; index++ )
        {
            QScrollArea *scroll = new QScrollArea();
            m_mainWidgets.append(scroll);
            scroll->setWidgetResizable(true);
            ui->mainStackedWidget->addWidget(scroll);
        }
    
        ui->mainStackedWidget->setCurrentIndex(0);
    
        m_mainWidgets[0]->setWidget(m_pManTabWidget = new ManTabWidget(m_client));
        m_mainWidgets[1]->setWidget(m_pMotionTestPage = new MotionTestWidget(m_client));
        m_mainWidgets[2]->setWidget(m_pMotionPage = new MotionPage(m_client));
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.