PDA

View Full Version : problem about mouse button events



vql
29th April 2008, 10:56
Hello.

I have a small problem about mouse button event. This is a simple program:



// ...

void MyWidget::mousePressEvent(QMouseEvent *e)
{
qWarning("mousePressEvent");
QWidget::mousePressEvent(e);
}

void MyWidget::mouseReleaseEvent(QMouseEvent *e)
{
qWarning("mouseReleaseEvent");
QWidget::mouseReleaseEvent(e);
}

// ...


When I press a left mouse button, and keep it. I drag to another position and press the middle the button (at this time, both left and middle mouse button are pressed because left mouse button is kept before), and after that, I release the left mouse button.

But why the system only write the message output:


mousePressEvent


It is mean that the mouseReleaseEvent isn't catched.

Please tell me how to solve this problem how to catch mouseReleaseEvent in this case. Thanks.

wysota
29th April 2008, 11:14
Could you reproduce the problem with the following code?


#include <QtGui>

class Widget : public QWidget {
public:
Widget() : QWidget(){}
protected:
void mousePressEvent(QMouseEvent *me){
qDebug("PRESS");
}
void mouseReleaseEvent(QMouseEvent *me){
qDebug("RELEASE");
}
};

int main(int argc, char **argv){
QApplication app(argc, argv);
Widget w;
w.show();
return app.exec();
}