Qt resize widget inside another widget

戏子无情 提交于 2020-01-25 03:29:06

问题


I have the following layout:

The black rectangles are QVBoxLayouts, the red one is a generic widget container and the blue little rectangle is my custom openGL widget.

I already set the resize policies for all layouts and widgets, but I can't get the openGL little widget to resize to the extent of his parent's area (the red rectangle in the image).

I'm a Qt beginner, perhaps I need to use signals and slots to resize the little blue openGL widget to the red one? But how?


回答1:


The QGLWidget should also be in a layout (of any layout type) to resize itself automatically when its parent is resized.

So, for instance, in the designer, left-click on the red "generic widget container", and choose a vertical layout.




回答2:


In Qt5.4 (i didn't test others) new QOpenGLWidget (inside layout) do not resized automatically in my case. I call

LayoutWidget->setGeometry(QRect(0, 0, event->size().width(), event->size().height()));

in resizeEvent(QResizeEvent *event) of parent widget.



来源:https://stackoverflow.com/questions/11612146/qt-resize-widget-inside-another-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!