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. Resize of scroll area widget not working
Forum Updated to NodeBB v4.3 + New Features

Resize of scroll area widget not working

Scheduled Pinned Locked Moved Solved General and Desktop
25 Posts 3 Posters 7.8k Views 3 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.
  • O Offline
    O Offline
    ofmrew
    wrote on last edited by
    #7

    Since the posting of the image is problematic, let m verbally explain the problem. I have a scroll area in a vertical layout with a horizontal layout of push buttons. Everything resizes except for the subclass of widget contained in the scroll area. In the code in a previous post, above, I set the widget, my subclass, to sizable. I put a debug in the resize event and it only one call to that method.

    Any thoughts?

    O 1 Reply Last reply
    0
    • O ofmrew

      Since the posting of the image is problematic, let m verbally explain the problem. I have a scroll area in a vertical layout with a horizontal layout of push buttons. Everything resizes except for the subclass of widget contained in the scroll area. In the code in a previous post, above, I set the widget, my subclass, to sizable. I put a debug in the resize event and it only one call to that method.

      Any thoughts?

      O Offline
      O Offline
      ofmrew
      wrote on last edited by
      #8

      @ofmrew alt text When the image uploaded successfully I got the correct link. Now you can see how the MainWindow is organized. The following code shows that I am trying to set canvas to be resized:

          ui->setupUi(this);
          ui->scrollArea->setWidgetResizable(true);
          ui->canvas->setBackgroundRole(QPalette::Base);
      

      The MainWindow and the pushbuttons all resize, and it appears that the scroll area resizes, but the canvas does not. I put an debug in resize and it is called only once.
      What is missing?

      O 1 Reply Last reply
      0
      • O ofmrew

        @ofmrew alt text When the image uploaded successfully I got the correct link. Now you can see how the MainWindow is organized. The following code shows that I am trying to set canvas to be resized:

            ui->setupUi(this);
            ui->scrollArea->setWidgetResizable(true);
            ui->canvas->setBackgroundRole(QPalette::Base);
        

        The MainWindow and the pushbuttons all resize, and it appears that the scroll area resizes, but the canvas does not. I put an debug in resize and it is called only once.
        What is missing?

        O Offline
        O Offline
        ofmrew
        wrote on last edited by
        #9

        @ofmrew Let me also show the current result of resizing the window:

        window

        You can see that the scroll area has been expanded but the contents of the canvas has not been updated to the new size.

        Any thoughts?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #10

          You can also change the size policy of your canvas to be Expanding.

          O 1 Reply Last reply
          0
          • S Sam

            You can also change the size policy of your canvas to be Expanding.

            O Offline
            O Offline
            ofmrew
            wrote on last edited by
            #11

            @Sam I tried that and got the same result. It appears that the vertical layout is getting the resize event and is propagating it to the horizontal layout and the scroll area, but for some reason it is not propagated to canvas. Originally I added a Widget to the scroll area and then propagated it to MyCanvas. Could the fact that Widget was promoted be the source of the problem.

            I put in a debug print in the resizeEvent of MyCanvas:

            qDebug() << "Resized" << this->parentWidget();

            Resized QWidget(0x99c680, name="scrollAreaWidgetContents")
            /home/xxx/build-Comprehensive2DInteractive-Desktop_

            I hope that this helps. Also, look at the image above, both the scrollAreaWidgetContents and canvas show there is no layout in the scrollArea.

            O 1 Reply Last reply
            0
            • O ofmrew

              @Sam I tried that and got the same result. It appears that the vertical layout is getting the resize event and is propagating it to the horizontal layout and the scroll area, but for some reason it is not propagated to canvas. Originally I added a Widget to the scroll area and then propagated it to MyCanvas. Could the fact that Widget was promoted be the source of the problem.

              I put in a debug print in the resizeEvent of MyCanvas:

              qDebug() << "Resized" << this->parentWidget();

              Resized QWidget(0x99c680, name="scrollAreaWidgetContents")
              /home/xxx/build-Comprehensive2DInteractive-Desktop_

              I hope that this helps. Also, look at the image above, both the scrollAreaWidgetContents and canvas show there is no layout in the scrollArea.

              O Offline
              O Offline
              ofmrew
              wrote on last edited by
              #12

              @ofmrew More info. I added a debug to the paint event, something I should have done when I add the one to resize event. As I drag the corner of the window the paint event is called, multiple times, but the rectangle is the same.
              The debug:
              qDebug() << "Paint Event" << e->rect();
              The results:
              Resized QWidget(0x14fe120, name="scrollAreaWidgetContents")
              Paint Event QRect(0,0 1011x661)
              Paint Event QRect(0,0 1011x661)
              Paint Event QRect(0,0 1011x661)
              . . . .
              I have set all the objects from canvas to main window the have expanding resize policies. What am I missing?

              O 1 Reply Last reply
              0
              • O ofmrew

                @ofmrew More info. I added a debug to the paint event, something I should have done when I add the one to resize event. As I drag the corner of the window the paint event is called, multiple times, but the rectangle is the same.
                The debug:
                qDebug() << "Paint Event" << e->rect();
                The results:
                Resized QWidget(0x14fe120, name="scrollAreaWidgetContents")
                Paint Event QRect(0,0 1011x661)
                Paint Event QRect(0,0 1011x661)
                Paint Event QRect(0,0 1011x661)
                . . . .
                I have set all the objects from canvas to main window the have expanding resize policies. What am I missing?

                O Offline
                O Offline
                ofmrew
                wrote on last edited by
                #13

                @ofmrew More info. I changed the debug:
                qDebug() << "Paint Event" << e->rect() << this->parentWidget()->rect();
                I get:
                Resized QWidget(0x11e5170, name="scrollAreaWidgetContents")
                Paint Event QRect(0,0 1011x661) QRect(0,0 1028x701)
                Paint Event QRect(0,0 1011x661) QRect(0,0 1029x702)
                Paint Event QRect(0,0 1011x661) QRect(0,0 1030x703)
                Paint Event QRect(0,0 1011x661) QRect(0,0 1031x704)
                Paint Event QRect(0,0 1011x661) QRect(0,0 1033x705)
                Paint Event QRect(0,0 1011x661) QRect(0,0 1035x706)
                . . . .

                The container is being resized, but it is not passing the resize event to the canvas, its contents.

                mrjjM O 2 Replies Last reply
                0
                • O ofmrew

                  @ofmrew More info. I changed the debug:
                  qDebug() << "Paint Event" << e->rect() << this->parentWidget()->rect();
                  I get:
                  Resized QWidget(0x11e5170, name="scrollAreaWidgetContents")
                  Paint Event QRect(0,0 1011x661) QRect(0,0 1028x701)
                  Paint Event QRect(0,0 1011x661) QRect(0,0 1029x702)
                  Paint Event QRect(0,0 1011x661) QRect(0,0 1030x703)
                  Paint Event QRect(0,0 1011x661) QRect(0,0 1031x704)
                  Paint Event QRect(0,0 1011x661) QRect(0,0 1033x705)
                  Paint Event QRect(0,0 1011x661) QRect(0,0 1035x706)
                  . . . .

                  The container is being resized, but it is not passing the resize event to the canvas, its contents.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #14

                  @ofmrew

                  Just as a note to

                  -Could the fact that Widget was promoted be the source of the problem.

                  Nope. Promotion is just a replacement feature.
                  The code inside setupUI is just plain the promotion type and nothing
                  extra is going on. 100% like new-ing the type yourself.

                  O 1 Reply Last reply
                  0
                  • O ofmrew

                    @ofmrew More info. I changed the debug:
                    qDebug() << "Paint Event" << e->rect() << this->parentWidget()->rect();
                    I get:
                    Resized QWidget(0x11e5170, name="scrollAreaWidgetContents")
                    Paint Event QRect(0,0 1011x661) QRect(0,0 1028x701)
                    Paint Event QRect(0,0 1011x661) QRect(0,0 1029x702)
                    Paint Event QRect(0,0 1011x661) QRect(0,0 1030x703)
                    Paint Event QRect(0,0 1011x661) QRect(0,0 1031x704)
                    Paint Event QRect(0,0 1011x661) QRect(0,0 1033x705)
                    Paint Event QRect(0,0 1011x661) QRect(0,0 1035x706)
                    . . . .

                    The container is being resized, but it is not passing the resize event to the canvas, its contents.

                    O Offline
                    O Offline
                    ofmrew
                    wrote on last edited by
                    #15

                    @ofmrew I think I see the problem. If you look at the Object Inspector image above, note that the scroll area is not contained in a layout. I know that I attempted to add a vertical layout that contained the scroll area and the horizontal layout. I tried selecting the scroll area and the horizontal layout and putting them in a vertical layout, but to no avail, all the layouts are grayed out.

                    Any solution or must I start again, but in what order.

                    The documentation seems to indicate that QtCreator Designer is not fully compatible with layouts, namely: "Qt's layout classes were designed for hand-written C++ code, allowing measurements to be specified in pixels for simplicity, so they are easy to understand and use. The code generated for forms created using Qt Designer also uses the layout classes. Qt Designer is useful to use when experimenting with the design of a form since it avoids the compile, link and run cycle usually involved in user interface development."

                    1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @ofmrew

                      Just as a note to

                      -Could the fact that Widget was promoted be the source of the problem.

                      Nope. Promotion is just a replacement feature.
                      The code inside setupUI is just plain the promotion type and nothing
                      extra is going on. 100% like new-ing the type yourself.

                      O Offline
                      O Offline
                      ofmrew
                      wrote on last edited by
                      #16

                      @mrjj That is what I assumed, but . . . .

                      1 Reply Last reply
                      0
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #17

                        hi
                        did you put layout into scrollAreaWidgetContents?

                        O 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          hi
                          did you put layout into scrollAreaWidgetContents?

                          O Offline
                          O Offline
                          ofmrew
                          wrote on last edited by
                          #18

                          @mrjj I tried but the layouts are all grayed out. Please look at the Objector Inspector image above . Just to the left of centralWidget there is an Icon that shows, or at least what I assume to be, a vertical layout. How do I put a layout into the scrollAreaWidgetContents?

                          O 1 Reply Last reply
                          0
                          • O ofmrew

                            @mrjj I tried but the layouts are all grayed out. Please look at the Objector Inspector image above . Just to the left of centralWidget there is an Icon that shows, or at least what I assume to be, a vertical layout. How do I put a layout into the scrollAreaWidgetContents?

                            O Offline
                            O Offline
                            ofmrew
                            wrote on last edited by
                            #19

                            @ofmrew I deleted canvas and added a layout to the scrollAreaWidgetContents and added the canvas. No luck.
                            alt text
                            In the image above note that it shows the scrollArea with not icon on the left, the scrollAreaWidgetContents with a red x on the layout, the vertical layout and finally the canvas with a red x. What should I expect to see?

                            mrjjM 1 Reply Last reply
                            0
                            • O ofmrew

                              @ofmrew I deleted canvas and added a layout to the scrollAreaWidgetContents and added the canvas. No luck.
                              alt text
                              In the image above note that it shows the scrollArea with not icon on the left, the scrollAreaWidgetContents with a red x on the layout, the vertical layout and finally the canvas with a red x. What should I expect to see?

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by mrjj
                              #20

                              @ofmrew
                              Is verticalLayout_2 one of the red one you can drag from left side ?
                              That would explain the image. ( so inside scrollArea widget is a free floating red layout) and
                              not a layout on scrollwidget in itself. ( by placing a widget and right click on area around it, and use layout menu)
                              alt text

                              O 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @ofmrew
                                Is verticalLayout_2 one of the red one you can drag from left side ?
                                That would explain the image. ( so inside scrollArea widget is a free floating red layout) and
                                not a layout on scrollwidget in itself. ( by placing a widget and right click on area around it, and use layout menu)
                                alt text

                                O Offline
                                O Offline
                                ofmrew
                                wrote on last edited by
                                #21

                                @mrjj I am not sure I understand what you are asking. I have deleted the canvas and the layout, so now I have what is shown in the image below:
                                alt text

                                The scroll area is selected. Now what should I do?

                                By the way on Postimage do not believe that 100% meand that the upload is finished, you must wait for the uploaded message, the image and a list of links.

                                mrjjM 1 Reply Last reply
                                0
                                • O ofmrew

                                  @mrjj I am not sure I understand what you are asking. I have deleted the canvas and the layout, so now I have what is shown in the image below:
                                  alt text

                                  The scroll area is selected. Now what should I do?

                                  By the way on Postimage do not believe that 100% meand that the upload is finished, you must wait for the uploaded message, the image and a list of links.

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by mrjj
                                  #22

                                  @ofmrew
                                  Ok :)
                                  Im am asking.
                                  How did you apply a layout to the ScrollAreaWidget ?

                                  -you must wait for the uploaded message, the image and a list of links.
                                  Yes and then select the direct link for image to show here.

                                  Ok, what i expect.
                                  1: place scrollarea on form
                                  2: place a widget inside scroll area
                                  3: right click scrollarea, and use the right click Layout menu to apply layout. ( no dragging)

                                  O 1 Reply Last reply
                                  2
                                  • mrjjM mrjj

                                    @ofmrew
                                    Ok :)
                                    Im am asking.
                                    How did you apply a layout to the ScrollAreaWidget ?

                                    -you must wait for the uploaded message, the image and a list of links.
                                    Yes and then select the direct link for image to show here.

                                    Ok, what i expect.
                                    1: place scrollarea on form
                                    2: place a widget inside scroll area
                                    3: right click scrollarea, and use the right click Layout menu to apply layout. ( no dragging)

                                    O Offline
                                    O Offline
                                    ofmrew
                                    wrote on last edited by
                                    #23

                                    @mrjj Success!!!!!

                                    My mistake it seems was not understanding the order of actions: place on the form the container for the widget, add the widget, right click on the container and then select layouts and select the layout. I was drag-and-dropping the layout, adding and resizing the widget to fit. Now I understand the order.

                                    Thanks very much. I can be accomplished in QtCreator.

                                    mrjjM 1 Reply Last reply
                                    0
                                    • O ofmrew

                                      @mrjj Success!!!!!

                                      My mistake it seems was not understanding the order of actions: place on the form the container for the widget, add the widget, right click on the container and then select layouts and select the layout. I was drag-and-dropping the layout, adding and resizing the widget to fit. Now I understand the order.

                                      Thanks very much. I can be accomplished in QtCreator.

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #24

                                      @ofmrew
                                      Its a classic. :)
                                      The draggable layouts seems the ones, until one find the right click
                                      menu. But the red layouts are for inserting into other layouts to stack/layout in other direction them but
                                      cannot be used directly on a widget as they dont scale to widgets area then.
                                      Also, now we talking about it.
                                      Using a splitter. You must place 2 widgets and select them, then you can use right menu to add splitter.
                                      (to be able to adjust area shared)

                                      1 Reply Last reply
                                      1
                                      • O Offline
                                        O Offline
                                        ofmrew
                                        wrote on last edited by
                                        #25

                                        Because of the number of posts about this issue, I thought it might be good to post a synopsis of the steps in creating:

                                        alt text

                                        The steps are: To design this window we do the following: 1. Place two pushbutton on the form, just above the status bar. Select both and right click on one of the selected pushbuttons. From the dialog chose Layout and Horizontal Layout. Now drop a scroll area above the pushbuttons. Right click on the main window and chose layout and Vertical Layout. We are not finished we must first add a Widget to the scroll area, i.e., drop the Widget with in the bounds of the scroll area object, then we must right click within the scroll area, but not within the Widget, chose Layouts and select vertical layout. The Widget will now resize with the other UI objects. The Widget is not what we want, we want a canvas, so select the Widget and promote it to MyCanvas. The key is to use the right mouse button to bring up the dialog.

                                        Hope this helps someone.

                                        1 Reply Last reply
                                        2

                                        • Login

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