How to fit QGrapicsView with QWidget (Taking the whole widget's size)
-
Hello, I implemented Canvas by using QGrapicsView and QGraphicsScene as a scene. And I passed the parent widget to QGrapicsView like this way:
class Canvas(QGrapicsView) __init__(self, scene, central_widget): super().__init__(scene, central_widget) # some codes here def customize_canvas(self): # Add Size Policy To Canvas, Make It Resizabl self.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) self.setMinimumSize(1210, 924) self.setTransformationAnchor(QGraphicsView.NoAnchor)
And my UI has: a widget with a layout and that layout contained some other Frames...
BUT I added the canvas to the widget itself NOT into the layout (for some reason, like to be the canvas in back with the whole widget's size and the other frames in front)As you can see, I added customize_canvas for setting sizePolicy... but that didn't work out. when I change the size of mainwindow that canvas doesn't change.
This is what I want.
Here is the description of the image above:In the Black box, we have the MainWindow.
In the Gray, we have a CentalWidget inside MainWindow.
Red represent the Canvas-Widget (child of centralWidget)Now I added the QGrapicsView which is the canvas into the Canvas-Widget (Not the gridLayout),
Then I added the gridLayout to Canvas-Widget... and added the other widgets on that layout with the BROWN color.The main idea with that approach is:
Having a Canvas which will draw shapes and having other menu above it...Why I didn't add the Canvas to the gridLayout? because if I did that, the canvas won't take the whole blue screen size and it will be limited by brown color (in the middle).
Why do i need the brown-widget?
They have some settings.. so they have a buttonsEdit:
I successfully created the design that is shown in the image above...
But my problem is how to fit that Canvas with the mainWindow, So any time users change the main window size... the canvas will change too.So, How to do that? and is my approche of the designe correct?
-
Hi,
If you want to have that handled for you, you need to use layouts.