Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt formlayout not expanding qplaintextedit vertically

I'm confused why a QPlainTextEdit widget will not resize vertically when added to a QFormLayout. In the code below the text field correctly scales up horizontally, but does not scale up vertically.

Can anyone explain this behavior and offer a solution? I've tried all the tricks I know to no avail.

from PyQt4 import QtGui

class Diag(QtGui.QDialog):

    def __init__(self, parent, *args, **kwargs):
        QtGui.QDialog.__init__(self, parent)
        layout = QtGui.QFormLayout(self)
        widg = QtGui.QPlainTextEdit(self)
        layout.addRow('Entry', widg)

if __name__ == '__main__': #pragma: no cover
    app = QtGui.QApplication([])
    window = Diag(None)
    window.show()
    app.exec_()

Here is an example of the QPlainTextEdit widget not resizing vertically: QPlainTextEdit added to QFormLayout but not resizing vertically

This is on Windows 7 using PyQt 4.5.2 and Python 32-bit 2.6.

Thanks.

like image 393
Jon Lauridsen Avatar asked Nov 16 '12 11:11

Jon Lauridsen


1 Answers

It seems that, by default, a QFormLayout will only resize the height of its fields according to their sizeHint.

To change this behaviour, adjust the vertical stretch as appropriate:

policy = widg.sizePolicy()
policy.setVerticalStretch(1)
widg.setSizePolicy(policy)
like image 112
ekhumoro Avatar answered Oct 14 '22 10:10

ekhumoro