What is QSizePolicy in pyside2

I think we should understand QSizePolicy class in order to understand layouting widgets in Qt. The size policy lets you provide default behavior for the layout management system.

actually, there is some information in Qt official documentation for QSizePolicy. but it was not easy to understand them for me.

so, I will explain about the policies as my understanding in this page.
first of all, I just introduce the policies in this page. and then, from next page, I will explain about them one by one more detailed.

there are 7 policies like below.


  • QSizePolicy::Fixed
  • QSizePolicy::Minimum
  • QSizePolicy::Maximum
  • QSizePolicy::Preferred
  • QSizePolicy::Expanding
  • QSizePolicy::MinimumExpanding
  • QSizePolicy::Ignored

for the background knowledge, every built-in widgets has its own size policy and the implementation of sizeHint() and sizeMinimunHint().

additionally, in order to expand and shrink, there have to be enough space for widget.
and whatever the size policy is, the size of widget cannot be larger than the maximum size and smaller than the minimum size.

Fixed means that the size of widget is completely fixed according to fixed size.
Minimum means that the size of sizeHint() function is minimal size. the size can be larger than the minimum size but can not be smaller than minimum size.
Maximum means that the size of sizeHint() function is maximum size. the size can be smaller than maximum size but can not be larger than maximum size.
Preferred means that the size of widget can be smaller and larger than the size of sizeHint(). and this is the default of QWidget class's policy.
Expanding means that the size of widget fill the space as much as possible. you can imagine something like slider.
MinimumExpanding means that the size of sizeHint() is minimal size. so it can be larger than minimal size. but can not be smaller than the minimal size.
Ignored means that the sizeHint() function is ignored. the size of widget will fill the space.

Comments

Popular posts from this blog

making menubar and menu on QML

let's start QML programming with PySide2

QSizePolicy Fixed example in pyside2