[Interest] mouse events: how to handle left and right button pressed?
Rui Maciel
rui.maciel at gmail.com
Sun Mar 4 16:59:54 CET 2012
I'm trying to handle mouse events which include the case where multiple
mouse buttons are pressed. The reference page on QMouseButton[1] states
that "[t]he button state is a combination of Qt::LeftButton
<http://doc.qt.nokia.com/4.7/qt.html#MouseButton-enum>, Qt::RightButton
<http://doc.qt.nokia.com/4.7/qt.html#MouseButton-enum>, Qt::MidButton
<http://doc.qt.nokia.com/4.7/qt.html#MouseButton-enum> using the OR
operator." From this, it would be expected that an event where multiple
buttons were pressed would be handled in a way similar to the following
code:
<code>
switch(event->buttons() )
{
case Qt::LeftButton:
std::cerr << "left" << std::endl;
break;
case Qt::RightButton:
std::cerr << "right" << std::endl;
break;
case (Qt::LeftButton | Qt::RightButton):
std::cerr << "both" << std::endl;
break;
default:
std::cerr << "other" << std::endl;
break;
}
</code>
Yet, when I try to compile this code, the following error message is
displayed:
<message>
InputState.c++:22:41: error: temporary of non-literal type
‘QFlags<Qt::MouseButton>’ in a constant expression
</message>
Does anyone know if it's possible to handle mouse events with multiple
buttons pressed through a switch() statement? If it isn't possible then
what alternatives are available?
Thanks in advance,
Rui Maciel
[1] http://doc.qt.nokia.com/4.7/qmouseevent.html#buttons
More information about the Interest
mailing list