[PyQt] need help with sizing QStackedWidgets

Eric Frederich eric.frederich at gmail.com
Mon Aug 26 14:36:03 BST 2013


Would appreciate some help here.
I don't like how these stacked widgets take up all of this vertical space
when the window is resized.
I have tried setting a size policy to minimum on the stacked widgets but no
luck.


On Fri, Aug 23, 2013 at 4:02 PM, Eric Frederich <eric.frederich at gmail.com>wrote:

> Here is a small example.
> I tried putting a vertical spacer on the bottom yet these stacked widgets
> want to take up space when resized.
>
> #!/usr/bin/env python
>
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
>
> class TestWidget(QWidget):
>     def __init__(self, labels, parent=None):
>         super(TestWidget, self).__init__(parent)
>
>         layout = QGridLayout()
>         for i, output in enumerate(labels):
>
>             layout.addWidget(QLabel(output), i, 0)
>             combo = QComboBox()
>             combo.addItems([
>                 "Slider",
>                 "Spinner",
>             ])
>             layout.addWidget(combo, i, 1)
>
>             stack = QStackedWidget()
>
>             horizontalSlider = QSlider()
>             horizontalSlider.setOrientation(Qt.Horizontal)
>
>             spinner = QSpinBox()
>
>             spinner.valueChanged.connect(horizontalSlider.setValue)
>             horizontalSlider.valueChanged.connect(spinner.setValue)
>
>             stack.addWidget(horizontalSlider)
>             stack.addWidget(spinner)
>
>             combo.currentIndexChanged.connect(stack.setCurrentIndex)
>
>             layout.addWidget(stack, i, 2)
>
>         vertical_spacer = QSpacerItem(0, 0, QSizePolicy.Minimum,
> QSizePolicy.Expanding)
>         layout.addItem(vertical_spacer, len(labels), 0, 1, 3)
>
>         self.setLayout(layout)
>
> if __name__ == '__main__':
>     import sys
>     app = QApplication(sys.argv)
>     ocw = TestWidget(['a', 'b', 'c', 'd', 'e'])
>     ocw.show()
>     sys.exit(app.exec_())
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130826/699f3630/attachment.html>


More information about the PyQt mailing list