QWidget expanding in QGraphicsScene/View
-
Hello,
Here is my issue.
I have a CustomWidget class which inherits from QWidget and has a UI file. This widget's main layout has its policy to x expanding, y expanding.I want this widget to fit in a QGraphicsView by taking all the space available by the view (horizontally and vertically)
For that, I created a QGraphicsScene, then used fitInView form the view.
Then used scene->addWidget(customwidget)The CustomWidget is centered in the view but doesnt fit it. Also, the widget's global dimensions in the view are the same as the ones in the CustomWidget's UI file , which means no automatic expansion ...
Cant figure out what's happening here :(
Cheers,
-
just resize your widget/graphicsproxywidget everytime the QGraphicsView resizes to the sceneRect().
Or play around with QGraphicsLayouts (not sure if there is one which does what you want though):
@
QGraphicsScene* scene;
QGraphicsWidget *widget = scene->addWidget(new QWidget);QGraphicsLinearLayout *layout = new QGraphicsLinearLayout;
layout->addItem(widget);QGraphicsWidget *form = new QGraphicsWidget;
form->setLayout(layout);
scene->addItem(form);
@ -
I will try this out :) Thanks.
By the way, is there a difference in this case between QGraphicsproxywidget or Widget (when adding it to the scene) ? -
QGraphicsProxyWidget derives from QGraphicsWidget
-
bq. just resize your widget/graphicsproxywidget everytime the QGraphicsView resizes to the sceneRect().
...or set the sceneRect to QGraphicsView's geometry and widget/graphicsproxywidget accordingly?
-
Indeed I think my issue was the scene->addWidget(customwidget) and not the scene which doesnt fit the view.
scene->addWidget(customwidget) might set the widget's position by default to the center of the scene and not at 0,0. What do you think?