PDA

View Full Version : mousePressEvent



mickey
21st March 2006, 06:41
Hi, I need to implement below in Widget::mousePressEvent(QmouseEvent* e)


if (Qt::LeftButton == e->state() ) && (Qt::RightButton == e->state() ) ...{
doSomething();
}
bui it take only a event...is there a way? Thanks

jpn
21st March 2006, 07:03
From docs (http://doc.trolltech.com/3.3/qmouseevent.html#state):
This means that if you have a QEvent::MouseButtonPress or a QEvent::MouseButtonDblClick state() will not include the mouse button that's pressed. But once the mouse button has been released, the QEvent::MouseButtonRelease event will have the button() that was pressed.

So try implementing that in mouse release event (and use e->button()) instead.

PS. ...and how could it be "left" AND "right" same time anyway..?

zlatko
21st March 2006, 15:11
You always can init some flag when you press one button and then use it in handler for other:)

wysota
21st March 2006, 15:36
PS. ...and how could it be "left" AND "right" same time anyway..?

If you have both buttons pressed. But the proper construction should be "e->state() & Qt::RightButton"