Hello first of all let me clarify that this is specific to PyQt and does
not existing in C++/Qt.
I am using PyQt 4.3.3 on Qt 4.4.0 on Kubuntu Hardy.
I attach three files.
1. test.py is the one that demonstrates the problem.
2. test.cpp is the equivalent C++ version that shows no problem.
3. test-sol.py is the Python version that works.
I wanted to draw a rubberband on a widget, and ended up finding this
bug. Everytime the mouseMoveEvent is processed, the value of the
variable rbOrigin (origin of the rubberband) is reset to the current
event position, thereby making it impossible for a proper rubberband to
be drawn. However, it appears that the mousePressEvent (which sets the
value of rbOrigin) is definitely not called by mistake as I don't get
any debug output.
The equivalent C++ version works without problems.
Using global coordinates on Python works around the bug but I don't see why.
Please look into the matter. Thanks for PyQt.
Shriramana Sharma.
References:
http://www.qtcentre.org/forum/f-qt-programming-2/t-qrubberband-doesnt-show-x11linux-16549.html
http://www.qtcentre.org/forum/f-qt-programming-2/t-unable-to-properly-implement-a-qrubberband-20109.html
// g++ rubberband-test.cpp -o rubberband-test -I /usr/include/qt4/ -lQtCore -lQtGui
# include <QtCore/QtCore>
# include <QtGui/QtGui>
class rubberBandWidget : public QWidget
{
public :
rubberBandWidget ( QWidget * parent = 0 ) : QWidget ( parent )
{
rubberBand = new QRubberBand ( QRubberBand :: Rectangle, this ) ;
}
protected :
void mousePressEvent ( QMouseEvent * event )
{
rbOrigin = event -> pos () ;
rubberBand -> setGeometry ( QRect ( rbOrigin, QSize () ) ) ;
rubberBand -> show () ;
}
void mouseMoveEvent ( QMouseEvent * event )
{
rubberBand -> setGeometry ( QRect ( rbOrigin, event -> pos () ) . normalized () ) ;
}
private :
QPoint rbOrigin ;
QRubberBand * rubberBand ;
} ;
int main ( int argc, char * argv [] )
{
QApplication app ( argc, argv ) ;
rubberBandWidget * widget = new rubberBandWidget ;
widget -> setGeometry ( 300, 300, 300, 300 ) ;
widget -> show () ;
return app . exec () ;
}
#! /usr/bin/env python
import sys
from PyQt4 . QtCore import *
from PyQt4 . QtGui import *
class rubberBandWidget ( QWidget ) :
def __init__ ( self, parent = None ) :
QWidget . __init__ ( self, parent )
self . rubberBand = QRubberBand ( QRubberBand . Rectangle, self )
def mousePressEvent ( self, event ) :
self . rbOrigin = event . pos ()
self . rubberBand . setGeometry ( QRect ( self . rbOrigin, QSize () ) )
self . rubberBand . show ()
print "press", self . rbOrigin
def mouseMoveEvent ( self, event ) :
self . rubberBand . setGeometry ( QRect ( self . rbOrigin, event . pos () ) . normalized () )
print "move", self . rbOrigin, event . pos (), self . rubberBand . geometry ()
app = QApplication ( sys . argv )
widget = rubberBandWidget ()
widget . setGeometry ( 300, 300, 300, 300 )
widget . show ()
app . exec_ ()
#! /usr/bin/env python
import sys
from PyQt4 . QtCore import *
from PyQt4 . QtGui import *
class rubberBandWidget ( QWidget ) :
def __init__ ( self, parent = None ) :
QWidget . __init__ ( self, parent )
self . rubberBand = QRubberBand ( QRubberBand . Rectangle, self )
def mousePressEvent ( self, event ) :
self . rbOrigin = self . mapFromGlobal ( event . globalPos () )
self . rubberBand . setGeometry ( QRect ( self . rbOrigin, QSize () ) )
self . rubberBand . show ()
def mouseMoveEvent ( self, event ) :
self . rubberBand . setGeometry ( QRect ( self . rbOrigin, self . mapFromGlobal ( event . globalPos () ) ) . normalized () )
app = QApplication ( sys . argv )
widget = rubberBandWidget ()
widget . setGeometry ( 300, 300, 300, 300 )
widget . show ()
app . exec_ ()
_______________________________________________
PyQt mailing list [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt