Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
15{
16 if (event->button() == Qt::LeftButton) {
17 // handle left mouse button here
18 } else {
19 // pass on other buttons to base class
21 }
22}
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
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}
57
58int main()
59{
60}
void mousePressEvent(QMouseEvent *event) override
[0]
Definition events.cpp:14
bool event(QEvent *event) override
[1]
Definition events.cpp:40
The QCheckBox widget provides a checkbox with a text label.
Definition qcheckbox.h:19
\inmodule QtCore
Definition qcoreevent.h:45
@ KeyPress
Definition qcoreevent.h:64
The QKeyEvent class describes a key event.
Definition qevent.h:424
\inmodule QtGui
Definition qevent.h:196
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
virtual void mousePressEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition qwidget.cpp:9483
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8866
static const int MyCustomEventType
Definition events.cpp:31
int main()
[1]
Definition events.cpp:58
@ LeftButton
Definition qnamespace.h:58
@ Key_Tab
Definition qnamespace.h:664
struct _cl_event * event
Definition moc.h:23