QSizePolicy Minimum in PySide2

if you set the size policy of any widget, the result of sizeHint() function come to be the minimal size of the widget. it means that the widget can be larger than sizeHint() but cannot be smaller than the sizeHint().

let's check it in example code.


from PySide2 import QtWidgets

app = QtWidgets.QApplication([])

window = QtWidgets.QWidget()
layout = QtWidgets.QHBoxLayout()
minimumButton = QtWidgets.QPushButton("Minimum Widget")

minimumButton.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)


layout.addWidget(minimumButton)
window.setLayout(layout)
window.show()

app.exec_()

at first, I created window and layout. and then, I created QPushButton to check the minimum size policy.

I changed the size policy of the button to Minimum. because the default size policy of QPushButton is minimum and fixed.

in the last, I execute Qt application. and then I run this application to check the result.





the first one has minimum sized button. I can't decrease the size of window anymore. because the window has the needed size for child widget at least.

and then, I increase the size of window. so that the size of button is also increased according to the size of window.










Comments

Popular posts from this blog

making menubar and menu on QML

QSizePolicy Fixed example in pyside2

let's start QML programming with PySide2