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
7class MyCheckBox : public QCheckBox
8{
9public:
10 void mousePressEvent(QMouseEvent *event) override;
11};
12
13//! [0]
14void 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
25class MyWidget : public QWidget
26{
27public:
28 bool event(QEvent *event) override;
29};
30
31static const int MyCustomEventType = 1099;
32
33class MyCustomEvent : public QEvent
34{
35public:
37};
38
39//! [1]
40bool 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]
void mousePressEvent(QMouseEvent *event) override
[0]
Definition events.cpp:14
bool event(QEvent *event) override
[1]
Definition events.cpp:40
static const int MyCustomEventType
Definition events.cpp:31