Question

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.

Was it helpful?

Solution

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)

OTHER TIPS

You should set the object in the last row of formlayout (see QPlainTextEdit), its vertical Stretch factor should not be 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top