[SOLVED] Shift + Mouseclick



  • 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 else

    I 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



  • 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.



  • 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]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.