Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
events.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
#
include
<
QCheckBox
>
5
#
include
<
QMouseEvent
>
6
7
class
MyCheckBox
:
public
QCheckBox
8
{
9
public
:
10
void
mousePressEvent
(QMouseEvent *event)
override
;
11
};
12
13
//! [0]
14
void
MyCheckBox
::
mousePressEvent
(QMouseEvent *event)
15
{
16
if
(event->button() == Qt::LeftButton) {
17
// handle left mouse button here
18
}
else
{
19
// pass on other buttons to base class
20
QCheckBox::mousePressEvent(event);
21
}
22
}
23
//! [0]
24
25
class
MyWidget
:
public
QWidget
26
{
27
public
:
28
bool
event
(QEvent *event)
override
;
29
};
30
31
static
const
int
MyCustomEventType
= 1099;
32
33
class
MyCustomEvent
:
public
QEvent
34
{
35
public
:
36
MyCustomEvent
() :
QEvent
((
QEvent
::
Type
)
MyCustomEventType
) {}
37
};
38
39
//! [1]
40
bool
MyWidget
::
event
(QEvent *event)
41
{
42
if
(event->type() == QEvent::KeyPress) {
43
QKeyEvent *ke =
static_cast
<QKeyEvent *>(event);
44
if
(ke->key() == Qt::Key_Tab) {
45
// special tab handling here
46
return
true
;
47
}
48
}
else
if
(event->type() ==
MyCustomEventType
) {
49
MyCustomEvent
*myEvent =
static_cast
<
MyCustomEvent
*>(event);
50
// custom event handling here
51
return
true
;
52
}
53
54
return
QWidget::event(event);
55
}
56
//! [1]
MyCheckBox
Definition
events.cpp:8
MyCheckBox::mousePressEvent
void mousePressEvent(QMouseEvent *event) override
[0]
Definition
events.cpp:14
MyCustomEvent
Definition
events.cpp:34
MyCustomEvent::MyCustomEvent
MyCustomEvent()
Definition
events.cpp:36
MyWidget
[24]
Definition
src_corelib_kernel_qobject.cpp:264
MyWidget::event
bool event(QEvent *event) override
[1]
Definition
events.cpp:40
MyCustomEventType
static const int MyCustomEventType
Definition
events.cpp:31
qtbase
src
corelib
doc
snippets
events
events.cpp
Generated on
for Qt by
1.14.0