[PyQt] Self-adjusting QTextEdit (PyQt4)

Wildemar Wildenburger wildemar at freakmail.de
Sat Apr 26 13:49:11 BST 2008


Hello folks,

I'm trying to write a notecard application, somewhat in the vein of 
Evernote --- basically a succession of little textboxes, one per note, 
stacked above one another. To that end I'd like a QTextEdit (or similar) 
that adjusts its height (with given width) so that it always shows all 
its text, never more, never less.

This is what I've come up with (complete runable example attached):

class MyText(gui.QTextEdit):
    def __init__(self, parent=None):
        gui.QTextEdit.__init__(self, parent)
        self.setVerticalScrollBarPolicy(core.Qt.ScrollBarAlwaysOff)
        self.connect(self, core.SIGNAL("textChanged()"), self.updateGeometry)
        policy = gui.QSizePolicy(gui.QSizePolicy.MinimumExpanding,
                                 gui.QSizePolicy.Minimum)
        policy.setHeightForWidth(True)
        self.setSizePolicy(policy)
    
    def heightForWidth(self, w):
        return self.document().size().toSize().height()

This does not work as I hoped, naturally. :(

How would I go about this?

regards,
/W
-------------- next part --------------
A non-text attachment was scrubbed...
Name: minimal.py
Type: text/x-python
Size: 3002 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20080426/1a4b3805/minimal.py


More information about the PyQt mailing list