How to let the QGraphicsView centered on the QWidget?
-
How to let the QGraphicsView centered on the QWidget?
-
Hi,
Does the QGraphicsView have a fixed size?
On your parent layout add horizontal and vertical spaces in a gridlayout. -
@Jeroentjehome The size of QGraphicsView may be changed by user. I want to let the QGraphicsView constantly centered on whenever user resize the widget.
Do you mean that I should add gridlayout in QWidget? -
Hi, in QtWidgets programs it are always the layouts that set the resize policies for the children widgets. Setting a parent for an QWidget will not do anything for the behavior of resizing. Only when a layout is set and the QGraphicsView is inserted into that layout will it behave according the layouts resize commands. In this case a QWidget as parent where the layout is set on. In your case is a full fit of the parent widget not what you need? So in your case, create a QMainWindow (or some other form or QDialog etc) and place a layout on that widget. Then place the QGraphicsView into that layout and tadaaaa, it is always full widget sized in your parent widget.
You might want to read up on the QLayout examples etc. That will explain a lot! -
@Jeroentjehome Thank you, I'll try it