Hi peeps,

I'm playing around with QPlainTextEdit and having the weirdest bug.

In my application, I've got keyboard shortcuts to scroll the TextEdit up and 
down by way of the QScrollBar.triggerAction() method, with arguments of 
SliderPageStepSub and SliderPageStepAdd respectively.

I also need to do some stuff when the scrollbar moves, so I bind the 
scrollbar's valueChanged() signal to the appropriate method.

It works all fine when the TextEdit is a QTextEdit.

It no longer works when the TextEdit is a QPlainTextEdit.

This is really bizarre, because the signal is emitted just fine when:
 - I move the slider around with the mouse;
 - I scroll with the mouse wheel;
 - I trigger the SliderSingleStepAdd/Sub actions instead (with Single instead 
of Page).

And before you bring up QScrollBar.setTracking, I used it and it doesn't 
change anything.

You will find a test case attached herein. Click the buttons to scroll up and 
down. Then do the same with the mouse. Compare.

This is with Qt 4.5.2 and SIP 4.9.1-snapshot-20091015 (the default Ubuntu 
version).

Anybody has any idea what's going on there? A Qt bug maybe?

Thanks.

-- S.
#!/usr/bin/python
## -*- coding: utf-8 -*-

import sys
import sip

from PyQt4 import QtCore, QtGui


class ExampleWidget( QtGui.QWidget ):

  def __init__( s ):

    QtGui.QWidget.__init__( s )

    layout = QtGui.QHBoxLayout( s )

    ## Create widgets for left column:

    l1 = QtGui.QVBoxLayout()
    layout.addLayout( l1 )

    s.text1 = QtGui.QTextEdit( s )
    s.text1.setPlainText( u"Some text here.\n" * 100 )

    b1up   = QtGui.QPushButton( "Scroll up!",   s )
    b1down = QtGui.QPushButton( "Scroll down!", s )

    l1.addWidget( s.text1 )
    l1.addWidget( b1up )
    l1.addWidget( b1down )

    s.connect( b1up,   QtCore.SIGNAL( "clicked()" ), s.text1Up )
    s.connect( b1down, QtCore.SIGNAL( "clicked()" ), s.text1Down )

    ## Create widgets for right column:

    l2 = QtGui.QVBoxLayout()
    layout.addLayout( l2 )

    s.text2 = QtGui.QPlainTextEdit( s )
    s.text2.setPlainText( u"Some other text here.\n" * 100 )

    b2up   = QtGui.QPushButton( "Scroll up!",   s )
    b2down = QtGui.QPushButton( "Scroll down!", s )

    l2.addWidget( s.text2 )
    l2.addWidget( b2up )
    l2.addWidget( b2down )

    s.connect( b2up,   QtCore.SIGNAL( "clicked()" ), s.text2Up )
    s.connect( b2down, QtCore.SIGNAL( "clicked()" ), s.text2Down )

    ## And set up the connections that demonstrate the bug:

    s.connect( s.text1.verticalScrollBar(), \
               QtCore.SIGNAL( "valueChanged( int )" ), s.hasValueChanged1 )

    s.connect( s.text2.verticalScrollBar(), \
               QtCore.SIGNAL( "valueChanged( int )" ), s.hasValueChanged2 )


  def hasValueChanged1( s, val ):

    print "QTextEdit has scrolled to position %d." % val


  def hasValueChanged2( s, val ):

    print "QPlainTextEdit has scrolled to position %d." % val


  def text1Up( s ):

    sb = s.text1.verticalScrollBar()
    sb.triggerAction( QtGui.QAbstractSlider.SliderPageStepSub )


  def text1Down( s ):

    sb = s.text1.verticalScrollBar()
    sb.triggerAction( QtGui.QAbstractSlider.SliderPageStepAdd )


  def text2Up( s ):

    sb = s.text2.verticalScrollBar()
    sb.triggerAction( QtGui.QAbstractSlider.SliderPageStepSub )


  def text2Down( s ):

    sb = s.text2.verticalScrollBar()
    sb.triggerAction( QtGui.QAbstractSlider.SliderPageStepAdd )


app = QtGui.QApplication( sys.argv )

widget = ExampleWidget()
widget.show()

app.exec_()
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to