How can one get Ctrl+Left mouse click
event in Qt widget. I am able to get key event from QObject::keyPressEvent()
and mouse click from QObject::mousePressEvent()
. But I need to capture both in the same function. Can someone give some pointer to right direction. Thanks.
Asked
Active
Viewed 3,098 times
3 Answers
2
You can try to use an additional variable, like:
private:
bool ctrlIsPressed = false;
protected:
void keyPressEvent(QKeyEvent *event)
{
if( event->key() == Qt::Key_Control )
ctrlIsPressed = true;
}
void keyReleaseEvent(QKeyEvent *event)
{
if( event->key() == Qt::Key_Control )
ctrlIsPressed = false;
}
void mousePressEvent()
{
if( ctrlIsPressed )
// ... Your code
}

JoshThunar
- 452
- 1
- 6
- 15
-
Actually I wanted to avoid this, but it could be done this way. Thanks. – Oli Feb 15 '17 at 16:59
2
You can call QMouseEvent::modifiers() to check whether it returns the value Qt::ControlModifier.

wedesoft
- 2,781
- 28
- 25
0
Check out this Stackoverflow.com question. I think it is exactly the issue you are having.

Community
- 1
- 1

Mike - SMT
- 14,784
- 4
- 35
- 79