[SOLVED] Shift + Mouseclick
-
wrote on 5 Jun 2012, 07:26 last edited by
Hi all
I got a question.
I have button that has to do 2 things.
When clicked:
Go to a function
When shift + clicked:
Go to somewhere elseI have tried it with a keypressEvent, catching the shift key and changing the connect(SIGNAL, SLOT), but it doesn't seem to catch that.
Then I tried to install an eventfilter, which results in nothing either. Anyone got any idea for me?
You would be of great help! Thanks
-
wrote on 5 Jun 2012, 08:03 last edited by
Hi,
the event filter should work if you do it correctly :-) How did you do it? Could you share some code?
The other option would be, subclass the button, overwrite mouse events and emit additional signals when shift click the button.
-
wrote on 5 Jun 2012, 08:11 last edited by
I think it is working. I don't know what I was doing wrong, but now it works fine.
The code:
@bool EventWidget::eventFilter(QObject *obj, QEvent *event)
{
//qDebug() << event->key();
if (event->type() == QEvent::MouseButtonPress)
{
if(Qt::ShiftModifier == QApplication::keyboardModifiers())
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if(mouseEvent)
{
if (mouseEvent->button() == Qt::LeftButton)
{
//I do the other thing here.
return true;
}
}
}
}
return QWidget::eventFilter(obj, event);
}@And this, apparently, works just fine. So its [SOLVED]
1/3