sorry, not QKeyEvent, but QMouseEvent
1. subclassing
{
if (e->modifiers() == Qt::ShiftModifier) {
//do what you need
return;
}
}
void MyPushButton::mousePressEvent(QMouseEvent *e)
{
if (e->modifiers() == Qt::ShiftModifier) {
//do what you need
return;
}
QPushButton::mousePressEvent(e);
}
To copy to clipboard, switch view to plain text mode
2. installFilter
...
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
);
}
...
pushButton->installEventFilter(this);
...
bool MyWidget::eventFilter(QObject *obj, QEvent *event)
{
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);
}
To copy to clipboard, switch view to plain text mode
Bookmarks