[PyQt] Missing scrollbar signal in QPlainTextEdit?

Henning Schröder henning.schroeder at gmail.com
Fri Dec 11 06:28:27 GMT 2009

Hello again!

On Fri, Dec 11, 2009 at 6:35 AM, Henning Schröder <
henning.schroeder at gmail.com> wrote:

> Hi!
> On Thu, Dec 10, 2009 at 4:35 PM, Sundance <sundance at ierne.eu.org> wrote:
>> Hi peeps,
>> I'm playing around with QPlainTextEdit and having the weirdest bug.
> I experienced the same problem. It would be nice if it would work same in
> QPlainTextEdit like with QTextEdit..
> Perhaps we should write a test in C++ to see if it is a Python problem or a
> Qt problem/bug.
I have looked at the source of QPlainTextEdit and QTextEdit. Actually the
implementations are not consistent.
QPlainTextEdit calls verticalBar.blockSignals(True) before it call setValue
which would otherwise emit valueChanged.

So, here is a hack to get the same behaviour like QTextEdit:

class ScrollBar(QScrollBar):
    def __init__(self, parent):
        QScrollBar.__init__(self, parent)
    def sliderChange(self, change):
        if self.signalsBlocked() and change ==

class PlainTextEdit(QPlainTextEdit):
    def __init__(self, parent):
        QPlainTextEdit.__init__(self, parent)
        self.vbar = ScrollBar(self)

Fortunately sliderChange is virtual and it is called right before emitting
valueChanged in setValue :)
Perhaps you could also monkey-patch sliderChange of the existing scroll-bar.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20091211/4866cc2a/attachment-0001.html

More information about the PyQt mailing list