Qt 5.10 Book Examples
chapter16
EventChange
KeyFilter.h
Go to the documentation of this file.
1
// ======================================================================
2
// KeyFilter.h
3
// ======================================================================
4
// This file is a part of the book
5
// "Qt 5.10 Professional programming with C++"
6
// http://qt-book.com
7
// ======================================================================
8
// Copyright (c) 2017 by Max Schlee
9
// ======================================================================
10
11
#pragma once
12
13
#include <QtWidgets>
14
15
// ======================================================================
16
class
KeyFilter
:
public
QObject {
17
protected
:
18
bool
eventFilter
(QObject* pobj, QEvent* pe)
19
{
20
if
(pe->type() == QEvent::KeyPress) {
21
if
(((QKeyEvent*)pe)->key() == Qt::Key_Z) {
22
QKeyEvent keyEvent(QEvent::KeyPress,
23
Qt::Key_A,
24
Qt::NoModifier,
25
"A"
26
);
27
QApplication::sendEvent(pobj, &keyEvent);
28
return
true
;
29
}
30
}
31
return
false
;
32
}
33
34
public
:
35
KeyFilter
(QObject* pobj = 0)
36
: QObject(pobj)
37
{
38
}
39
};
40
KeyFilter::eventFilter
bool eventFilter(QObject *pobj, QEvent *pe)
Definition:
KeyFilter.h:18
KeyFilter
Definition:
KeyFilter.h:16
KeyFilter::KeyFilter
KeyFilter(QObject *pobj=0)
Definition:
KeyFilter.h:35
Generated by
1.8.14