I&#39;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.<br>

<br>Screenshot here: <a href="http://www.netdepot.org/personal/qstackedlayout_demo.png">http://www.netdepot.org/personal/qstackedlayout_demo.png</a><br><br>Why does this happen? How can I prevent it?<br>
<br>#################################################################<br><br>from PyQt4 import QtCore, QtGui<br>import sys<br><br>class MyDialog(QtGui.QDialog):<br>    <br>    def __init__(self, parent=None):<br>        super(MyDialog, self).__init__(parent)<br>

        <br>        lineEdit1 = QtGui.QLineEdit(&quot;lineEdit1&quot;)<br>        lineEdit2 = QtGui.QLineEdit(&quot;lineEdit2&quot;)<br>        <br>        stackedLayout = QtGui.QStackedLayout()<br>        stackedLayout.addWidget(lineEdit2)<br>

        <br>        mainLayout = QtGui.QHBoxLayout()<br>        mainLayout.addWidget(lineEdit1)<br>        mainLayout.addLayout(stackedLayout)<br>        <br>        self.setLayout(mainLayout)<br>        self.setWindowTitle(&quot;QStackedLayout demo&quot;)<br>

<br>if __name__ == &quot;__main__&quot;:<br>    app = QtGui.QApplication(sys.argv)<br>    dialog = MyDialog()<br>    dialog.show()<br>    app.exec_()<br><br>