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. Expand QScrollArea after child widget reloading
Forum Updated to NodeBB v4.3 + New Features

Expand QScrollArea after child widget reloading

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.1k 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.
  • K Offline
    K Offline
    Kolya
    wrote on last edited by Kolya
    #1

    Hey guys,

    I have a tab widget (QTabWidget), which consists of pages (subclassed from QWidget).
    One of the tab pages acts as a navigation page, by having buttons: next and back to view the content of the dedicated page. This tab page has a method setCurrentPageIndex() so that I could inform it which page to load for viewing. When the tab widget sends a signal currentChanged(), I call setCurrentPageIndex(0) on the tab page to instruct the load the first page.

    This tab page when constructed only internally creates QScrollArea and rest of the setup is done when setCurrentPageIndex() is triggered.

    Here is code extract from setCurrentPageIndex(). All the widgets and layouts are recreated from scratch and I delete previously setup child widget in QScrollArea.

    auto pageLayout = new QVBoxLayout();
    // Populate it with wigets
    
    auto pageWidget = new QWidget();
    pageWidget->setLayout(pageLayout);
    
    auto oldPageWidget = mScrollArea->takeWidget();
    if (oldPageWidget != nullptr)
         oldPageWidget->deleteLater();
    
    mScrollArea->setWidget(pageWidget);
    mScrollArea->setWidgetResizable(true); 
    

    Despite applying mScrollArea->setWidgetResizable(true), the scroll area does not expand to the whole size of the tab page. I did try pageWidget->resize() but did not get any changes.

    0_1548153024159_Screen.png

    Also, when I was working initially on this tab page without navigation logic yet and the widgets were setup only once when the page is created (not each time setCurrentPageIndex() is called) the QScrollArea would expand to the whole tab page size.

    Anything odd you notice here? Could it be update/refresh issue?

    Thanks!

    jsulmJ 1 Reply Last reply
    0
    • K Kolya

      Hey guys,

      I have a tab widget (QTabWidget), which consists of pages (subclassed from QWidget).
      One of the tab pages acts as a navigation page, by having buttons: next and back to view the content of the dedicated page. This tab page has a method setCurrentPageIndex() so that I could inform it which page to load for viewing. When the tab widget sends a signal currentChanged(), I call setCurrentPageIndex(0) on the tab page to instruct the load the first page.

      This tab page when constructed only internally creates QScrollArea and rest of the setup is done when setCurrentPageIndex() is triggered.

      Here is code extract from setCurrentPageIndex(). All the widgets and layouts are recreated from scratch and I delete previously setup child widget in QScrollArea.

      auto pageLayout = new QVBoxLayout();
      // Populate it with wigets
      
      auto pageWidget = new QWidget();
      pageWidget->setLayout(pageLayout);
      
      auto oldPageWidget = mScrollArea->takeWidget();
      if (oldPageWidget != nullptr)
           oldPageWidget->deleteLater();
      
      mScrollArea->setWidget(pageWidget);
      mScrollArea->setWidgetResizable(true); 
      

      Despite applying mScrollArea->setWidgetResizable(true), the scroll area does not expand to the whole size of the tab page. I did try pageWidget->resize() but did not get any changes.

      0_1548153024159_Screen.png

      Also, when I was working initially on this tab page without navigation logic yet and the widgets were setup only once when the page is created (not each time setCurrentPageIndex() is called) the QScrollArea would expand to the whole tab page size.

      Anything odd you notice here? Could it be update/refresh issue?

      Thanks!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Kolya Your scroll area seems not to be in a layout

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • K Offline
        K Offline
        Kolya
        wrote on last edited by Kolya
        #3

        Hey @jsulm! I am not exactly sure I follow what you refer to by "not in the layout". From what I understand in the documentation, QScrollArea is not a part of the layout explicitly. The QScrollArea expects a child widget to be set (setWidget) and the child widget should have layout already setup on it. This is how I am creating QScrollArea

        TestPage::TestPage(Test* test, QWidget* parent)
            : QWidget(parent)
            , mTest(test)
        {
            setupWidgets();
        }
        
        void TestPage::setupWidgets()
        {
            // Create Previous, Next buttons
            auto navigationLayout = new QHBoxLayout();
            // Add Previous, Next buttons
        
            mPageLayout = new QVBoxLayout();
            mPageLayout->addLayout(navigationLayout);
        
            auto pageWidget = new QWidget();
            pageWidget->setLayout(mPageLayout);
        
            mScrollArea = new QScrollArea(this);
            mScrollArea->setWidgetResizable(true);
            mScrollArea->setWidget(pageWidget);
        
            setCurrentPageIndex(0);
        }
        

        Thanks!

        jsulmJ 1 Reply Last reply
        0
        • K Offline
          K Offline
          Kolya
          wrote on last edited by
          #4

          Guys, I managed to fix it by subclassing TestPage from QScrollArea, which now works for me as expected. Thank you!

          1 Reply Last reply
          0
          • K Kolya

            Hey @jsulm! I am not exactly sure I follow what you refer to by "not in the layout". From what I understand in the documentation, QScrollArea is not a part of the layout explicitly. The QScrollArea expects a child widget to be set (setWidget) and the child widget should have layout already setup on it. This is how I am creating QScrollArea

            TestPage::TestPage(Test* test, QWidget* parent)
                : QWidget(parent)
                , mTest(test)
            {
                setupWidgets();
            }
            
            void TestPage::setupWidgets()
            {
                // Create Previous, Next buttons
                auto navigationLayout = new QHBoxLayout();
                // Add Previous, Next buttons
            
                mPageLayout = new QVBoxLayout();
                mPageLayout->addLayout(navigationLayout);
            
                auto pageWidget = new QWidget();
                pageWidget->setLayout(mPageLayout);
            
                mScrollArea = new QScrollArea(this);
                mScrollArea->setWidgetResizable(true);
                mScrollArea->setWidget(pageWidget);
            
                setCurrentPageIndex(0);
            }
            

            Thanks!

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Kolya said in Expand QScrollArea after child widget reloading:

            I am not exactly sure I follow what you refer to by "not in the layout"

            What I mean is: if the scroll area is not managed by a layout (or its size by you manually) it will not be resized if you resize the widget where this scroll area is located.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1

            • Login

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