Widgets with SizePolicy there is no effects
-
Why the sizePolicy doesn't affect widgets that aren't in layout?
here is an example:
from PyQt5 import QtWidgets app = QtWidgets.QApplication([]) window = QtWidgets.QWidget() window.setGeometry(50, 50, 500, 300) test_widget = QtWidgets.QWidget(window) test_widget.setMinimumSize(100, 100) test_widget.setStyleSheet("background-color:red") size_policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) test_widget.setSizePolicy(size_policy) window.show() app.exec()
But that doesn't work, if you changed the main window size the red box still has the same size.
So how can I make that red box resizeable when the parent (main window) is changing?.
Can I achieve that without using layouts? -
@Pythonic-person said in Widgets with SizePolicy there is no effects:
Can I achieve that without using layouts?
Why don't you want to use layouts?
If you do not use layouts then you have to size and position your widgets by yourself. -
Why don't you want to use layouts?
Actually, Because I added another widget to that layout. And I want to add Canvas to the main widget not in that layout so I can have: Canvas in the back, and other menus in front (Adding canvas to that widget allow canvas taking the whole size of that widget)
@jsulm said in Widgets with SizePolicy there is no effects:
If you do not use layouts then you have to size and position your widgets by yourself.
So the sizePolicy won't work, right? Then how can I achieve that? Do you mean taking the main window size and then change the widget size with the code?
-
@Pythonic-person said in Widgets with SizePolicy there is no effects:
So the sizePolicy won't work, right? Then how can I achieve that?
By using layouts
-
@Pythonic-person said in Widgets with SizePolicy there is no effects:
Do you mean taking the main window size and then change the widget size with the code?
You either use one of the provided layout mechanisms, develop you your only layout implementation, or you do all the resizing of contained widgets yourself 1990's style.
If you wish to do it yourself then you need to override the resizeEvent() of the container widget and resize the contained widgets yourself using whatever logic you see fit.