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. Making Entire Dialog Scrollable
Forum Updated to NodeBB v4.3 + New Features

Making Entire Dialog Scrollable

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 2.8k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    RayGunYoda
    wrote on 10 Aug 2020, 16:46 last edited by
    #1

    I have existing dialog designs that were created using the qt designer. These dialogs are meant to be shown at their maximum size, but they are re-sizable (can only make smaller). When they are dragged to be smaller, my goal is to make horizontal and vertical scroll bars appear to scroll through the entire dialog. These scroll bars should mimic scrollbars for most major applications (eg. after searching for something in chrome, horizontal and vertical scroll bars appear when resizing the window).

    From what I have read, people suggest using QScrollArea with a QLayout, but I am not sure how to make this work for an existing dialog design (without a main layout). Maybe I just don't understand how to use layouts correctly, but if I right click the dialog in qt designer and click on any layout, everything moves and completely changes the location and design of the dialog. What is the proper way to add the scrolling functionality as described without having to redesign the dialog to use embedded layouts?

    J 1 Reply Last reply 10 Aug 2020, 18:23
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 10 Aug 2020, 18:05 last edited by
      #2

      Hi and welcome to devnet,

      It's not QScrollArea + layout. You set a widget as the QScrollArea content and then put the rest in a layout that you apply to that widget.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R RayGunYoda
        10 Aug 2020, 16:46

        I have existing dialog designs that were created using the qt designer. These dialogs are meant to be shown at their maximum size, but they are re-sizable (can only make smaller). When they are dragged to be smaller, my goal is to make horizontal and vertical scroll bars appear to scroll through the entire dialog. These scroll bars should mimic scrollbars for most major applications (eg. after searching for something in chrome, horizontal and vertical scroll bars appear when resizing the window).

        From what I have read, people suggest using QScrollArea with a QLayout, but I am not sure how to make this work for an existing dialog design (without a main layout). Maybe I just don't understand how to use layouts correctly, but if I right click the dialog in qt designer and click on any layout, everything moves and completely changes the location and design of the dialog. What is the proper way to add the scrolling functionality as described without having to redesign the dialog to use embedded layouts?

        J Offline
        J Offline
        JonB
        wrote on 10 Aug 2020, 18:23 last edited by
        #3

        @RayGunYoda said in Making Entire Dialog Scrollable:

        without having to redesign the dialog to use embedded layouts

        As @SGaist has said. But your dialog should already have a layout, are you saying yours does not have one? There may be a better way for dialogs, but for your scrolling I think you're supposed to have:

        QDialog -> layout -> QScrollArea -> QWidget -> layout -> all the widgets you have on it now.
        
        1 Reply Last reply
        1
        • R Offline
          R Offline
          RayGunYoda
          wrote on 10 Aug 2020, 19:23 last edited by
          #4

          @JonB the dialog does not have a layout. Since it sounds like that having a layout is a requirement for scrolling, is there a way to insert all the widgets into a layout such that their positions stay the same as they are now?

          I found this code in another thread online:

          QScrollArea *scroll = new QScrollArea(this);
           
          QWidget *viewport = new QWidget(this);
          scroll->setWidget(viewport);
           
          QHBoxLayout *l = new QHBoxLayout(viewport);
          viewport->setLayout(l);
           
          // add all dialog widgets to layout l
          // ... adding widgets ...
           
          // Add a layout for QDialog
          QHBoxLayout *dialog_layout = new QHBoxLayout(dialog);
          this->setLayout(dialog_layout);
          this->layout()->addWidget(scroll); 
          

          I put this code in the constructor for my dialog. Firstly, I am not sure how to add all of the widgets to the layout. I tried this:

          QList<QWidget*> list = this->findChildren<QWidget*>();
          for (QWidget * w : list)
              l->addWidget(w);
          

          But this crashes. I also tried manually listing each widget (ie l->addWidget(ui->widgetName)), but this shows just a blank rectangle (also does not show scroll bars when the dialog is dragged to be smaller).

          Do you have any suggestions for what to do to get the scrollbar functionality working while maintaining the positioning of the widgets I already have?

          1 Reply Last reply
          0

          1/4

          10 Aug 2020, 16:46

          • Login

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