Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Scroll Bars Missing from QScrollArea
QtWS25 Last Chance

Scroll Bars Missing from QScrollArea

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    graniteDev
    wrote on last edited by
    #1

    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.

    raven-worxR 1 Reply Last reply
    0
    • G graniteDev

      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.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        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));
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        G 1 Reply Last reply
        2
        • VRoninV VRonin

          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));
          
          G Offline
          G Offline
          graniteDev
          wrote on last edited by graniteDev
          #4

          @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));
          
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved