[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] need help with sizing QStackedWidgets
From: Eric Frederich <eric.frederich () gmail ! com>
Date: 2013-08-26 14:34:57
Message-ID: CAAoZyYN1uCKO4+89TbaX0UL8UZRWN-0xEM0EmrY45y++cO8sGA () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Replying to self with a solution in case someone else comes across this
problem.
david_boddie on freenode's #pyqt channel helped me out.
A solution was to call....
layout.setRowStretch(len(labels), 1)
... after adding the spacer.
Another solution was to nest the grid layout into a BoxLayout and call
addStretch.
On Mon, Aug 26, 2013 at 9:36 AM, Eric Frederich <eric.frederich@gmail.com>wrote:
> 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@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_())
>>
>>
>
[Attachment #5 (text/html)]
<div dir="ltr"><div><div><div><div>Replying to self with a solution in case someone \
else comes across this problem.<br></div>david_boddie on freenode's #pyqt channel \
helped me out.<br><br></div>A solution was to call....<br> \
layout.setRowStretch(len(labels), 1)<br></div>... after adding the \
spacer.<br><br></div>Another solution was to nest the grid layout into a BoxLayout \
and call addStretch.<br></div><div class="gmail_extra"><br><br><div \
class="gmail_quote"> On Mon, Aug 26, 2013 at 9:36 AM, Eric Frederich <span \
dir="ltr"><<a href="mailto:eric.frederich@gmail.com" \
target="_blank">eric.frederich@gmail.com</a>></span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> <div dir="ltr"><div>Would appreciate some help \
here.<br></div>I don't like how these stacked widgets take up all of this \
vertical space when the window is resized.<br>I have tried setting a size policy to \
minimum on the stacked widgets but no luck.<br>
</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div \
class="gmail_quote">On Fri, Aug 23, 2013 at 4:02 PM, Eric Frederich <span \
dir="ltr"><<a href="mailto:eric.frederich@gmail.com" \
target="_blank">eric.frederich@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">Here is a small example.<br>I tried putting a \
vertical spacer on the bottom yet these stacked widgets want to take up space when \
resized.<br>
<br>#!/usr/bin/env python<br><br>from PyQt4.QtCore import *<br>from PyQt4.QtGui \
import *<br> <br>class TestWidget(QWidget):<br> def __init__(self, labels, \
parent=None):<br> super(TestWidget, self).__init__(parent)<br><br> \
layout = QGridLayout()<br> for i, output in enumerate(labels):<br><br>
layout.addWidget(QLabel(output), i, 0)<br> combo = \
QComboBox()<br> combo.addItems([<br> \
"Slider",<br> "Spinner",<br> ])<br> \
layout.addWidget(combo, i, 1)<br>
<br> stack = QStackedWidget()<br><br> horizontalSlider = \
QSlider()<br> horizontalSlider.setOrientation(Qt.Horizontal)<br><br> \
spinner = QSpinBox()<br><br> \
spinner.valueChanged.connect(horizontalSlider.setValue)<br>
horizontalSlider.valueChanged.connect(spinner.setValue)<br><br> \
stack.addWidget(horizontalSlider)<br> stack.addWidget(spinner)<br><br> \
combo.currentIndexChanged.connect(stack.setCurrentIndex)<br>
<br> layout.addWidget(stack, i, 2)<br><br> vertical_spacer = \
QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding)<br> \
layout.addItem(vertical_spacer, len(labels), 0, 1, 3)<br><br> \
self.setLayout(layout)<br>
<br>if __name__ == '__main__':<br> import sys<br> app = \
QApplication(sys.argv)<br> ocw = TestWidget(['a', 'b', \
'c', 'd', 'e'])<br> ocw.show()<br> \
sys.exit(app.exec_())<br>
<br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic