The resizePolicy module contains the ResizePolicy class which encapsulates a specific policy for resizing widgets.
The ResizePolicy encapsulates a specific policy for resizing widgets.
The possible resize policies are:
- Fixed – The size never changes
- Expanding – The size expands
For a specific policy, the ResizePolicy class can return the correct size for a widget, given the widget’s current size as well as the size of all of the widget’s child widgets.
For the Fixed resize policy: the size will always remain the same.
For the Expanding resize policy: the size will always expand to fit all of the widget’s children.
Example:
from PyQt4 import QtCore
from pyamp.ui.qt import ResizePolicy
# Create the size of the widget, and the list of sizes for all of
# the widget's children
size = QtCore.QSize(100, 200)
childSizes = [QtCore.QSize(200, 500), QtCore.QSize(300, 400)]
# Get the list of widths and heights for the child widgets
childWidths = map(QtCore.QSize.width, childSizes)
childHeights = map(QtCore.QSize.width, childSizes)
# Both of these return: 100
# Which is the given value of width
ResizePolicy.getSize(ResizePolicy.Fixed, size.width(), childWidths)
ResizePolicy.getWidth(ResizePolicy.Fixed, size, childSizes)
# Both of these return: 900
# Which is the sum of the childHeights list
ResizePolicy.getSize(ResizePolicy.Expanding, size.height(),
childHeights)
ResizePolicy.getHeight(ResizePolicy.Fixed, size, childSizes)
For the given resize policy, get the correct height for the size of the widget as well as the size of all of the widget’s children.
Get the correct size based on the given resize policy.
resizePolicy – The resize policy
size – The main single size (width or height) of the widget
of widgets’s children
For the given resize policy, get the correct width for the size of the widget as well as the size of all of the widget’s children.