Preferred QSizePolicy in PySide2
preferred policy is very flexible policy. the size of widget can be smaller and larger than sizeHint().
let's check the example code right now.
I created one button and set the property of size policy to preferred for both of horizontal and vertical policies.
then, I run the application.
first one is default size that evaluated from minimumSizeHint() function. every built-in widgets has its own reimplemented size hint function.
I expected the size of widget is smaller when I decreased the size of window. but the size of widget is not smaller than first image. because minimum size is there.
reversely, when I increased the size of window, the size of widget is also increased.
let's check the example code right now.
from PySide2 import QtWidgets, QtCore app = QtWidgets.QApplication([]) window = QtWidgets.QWidget() layout = QtWidgets.QHBoxLayout() PreferredButton = QtWidgets.QPushButton("Preferred Widget") PreferredButton.setSizePolicy(QtWidgets.QSizePolicy.Preferred , QtWidgets.QSizePolicy.Preferred) layout.addWidget(PreferredButton) window.setLayout(layout) window.show() app.exec_()
I created one button and set the property of size policy to preferred for both of horizontal and vertical policies.
then, I run the application.
first one is default size that evaluated from minimumSizeHint() function. every built-in widgets has its own reimplemented size hint function.
I expected the size of widget is smaller when I decreased the size of window. but the size of widget is not smaller than first image. because minimum size is there.
reversely, when I increased the size of window, the size of widget is also increased.
Comments
Post a Comment