QPushButton on Shift+Click?
Hi All,
I want to implement a QPushButton in such a way that it do something when user click it
for which I can use clicked() signal but I also want that when user click while shift button is pressed then it will do something else.
How can I do it?
Thanks
Vishal Chauhan
Re: QPushButton on Shift+Click?
you can subclass QPushButton and reimplement keyPressEvent or you can install event fillter for your button and process QKeyEvent.
Re: QPushButton on Shift+Click?
Thanks for reply.
Can you give some sample code for doing it.
Re: QPushButton on Shift+Click?
sorry, not QKeyEvent, but QMouseEvent :)
1. subclassing
Code:
{
if (e->modifiers() == Qt::ShiftModifier) {
//do what you need
return;
}
}
2. installFilter
Code:
...
pushButton->installEventFilter(this);
...
{
if (obj
== pushButton
&& event
->type
() == QEvent::MouseButtonPress) { QMouseEvent *mouseEvent
= static_cast<QMouseEvent
*>
(event
);
if (event->modifiers() == Qt::ShiftModifier) {
//do what you need
return true;
}
}
return QWidget::eventFilter(obj, event
);
}