[PyQt] Why is QStackedLayout so tall?

Jugdish jugdizh at gmail.com
Wed Sep 9 17:52:41 BST 2009


I'd like to use QStackedLayout to put some QLineEdit widgets in, with only
one visible at a time. For some reason, whenever I put a widget inside a
QStackedLayout, it displays much taller than it normally would. Below is a
small example to demonstrate this -- compare the height of the QLineEdit
outside the QStackedLayout vs. the one inside.

Screenshot here: http://www.netdepot.org/personal/qstackedlayout_demo.png

Why does this happen? How can I prevent it?

#################################################################

from PyQt4 import QtCore, QtGui
import sys

class MyDialog(QtGui.QDialog):

    def __init__(self, parent=None):
        super(MyDialog, self).__init__(parent)

        lineEdit1 = QtGui.QLineEdit("lineEdit1")
        lineEdit2 = QtGui.QLineEdit("lineEdit2")

        stackedLayout = QtGui.QStackedLayout()
        stackedLayout.addWidget(lineEdit2)

        mainLayout = QtGui.QHBoxLayout()
        mainLayout.addWidget(lineEdit1)
        mainLayout.addLayout(stackedLayout)

        self.setLayout(mainLayout)
        self.setWindowTitle("QStackedLayout demo")

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    dialog = MyDialog()
    dialog.show()
    app.exec_()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090909/2644965e/attachment.html


More information about the PyQt mailing list