Resize of scroll area widget not working
-
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.pngu put that instead of "image url"
-
The URL is invalid ?
-
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?
-
@ofmrew 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? -
@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.
-
@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? -
@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.
-
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. -
@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."
-
hi
did you put layout into scrollAreaWidgetContents? -
@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?
-
@ofmrew I deleted canvas and added a layout to the scrollAreaWidgetContents and added the canvas. No luck.
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? -
@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)