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 8.2k 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
    #1

    When I try to add my image I get:
    ![alt text](image url)
    What is expected?

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

    The add code is fine, but what is expected for the image?

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

      ITs expected an URL to external image. (should end in image .ext)
      like
      https://doc.qt.io/qt-5.10/images/used-in-examples/gallery/images/qt-logo@4x.png

      u put that instead of "image url"

      O 1 Reply Last reply
      0
      • mrjjM mrjj

        ITs expected an URL to external image. (should end in image .ext)
        like
        https://doc.qt.io/qt-5.10/images/used-in-examples/gallery/images/qt-logo@4x.png

        u put that instead of "image url"

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

        @mrjj alt text

        Lets see if this works!

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

          The URL is invalid ?
          alt text

          1 Reply Last reply
          0
          • O ofmrew

            @mrjj alt text

            Lets see if this works!

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

            @ofmrew Apparently not. I tried to post to Postimage.org, but that seems to have failed. Is there a better way?

            O 1 Reply Last reply
            0
            • O ofmrew

              @ofmrew Apparently not. I tried to post to Postimage.org, but that seems to have failed. Is there a better way?

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

              @ofmrew On Postimage.org it shows the file as 100% what ever that means; does it actually mean that the file is there or something else. How can I check?

              1 Reply Last reply
              0
              • 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

                                          • Login

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