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
qabstractbutton.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QABSTRACTBUTTON_H
6#define QABSTRACTBUTTON_H
7
8#include <QtWidgets/qtwidgetsglobal.h>
9#include <QtGui/qicon.h>
10#if QT_CONFIG(shortcut)
11# include <QtGui/qkeysequence.h>
12#endif
13#include <QtWidgets/qwidget.h>
14
15QT_REQUIRE_CONFIG(abstractbutton);
16
17QT_BEGIN_NAMESPACE
18
19
20class QButtonGroup;
21class QAbstractButtonPrivate;
22
23class Q_WIDGETS_EXPORT QAbstractButton : public QWidget
24{
25 Q_OBJECT
26
27 Q_PROPERTY(QString text READ text WRITE setText)
28 Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
29 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
30#ifndef QT_NO_SHORTCUT
31 Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)
32#endif
33 Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable)
34 Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled USER true)
35 Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat)
36 Q_PROPERTY(bool autoExclusive READ autoExclusive WRITE setAutoExclusive)
37 Q_PROPERTY(int autoRepeatDelay READ autoRepeatDelay WRITE setAutoRepeatDelay)
38 Q_PROPERTY(int autoRepeatInterval READ autoRepeatInterval WRITE setAutoRepeatInterval)
39 Q_PROPERTY(bool down READ isDown WRITE setDown DESIGNABLE false)
40
41public:
42 explicit QAbstractButton(QWidget *parent = nullptr);
43 ~QAbstractButton();
44
45 void setText(const QString &text);
46 QString text() const;
47
48 void setIcon(const QIcon &icon);
49 QIcon icon() const;
50
51 QSize iconSize() const;
52
53#ifndef QT_NO_SHORTCUT
54 void setShortcut(const QKeySequence &key);
55 QKeySequence shortcut() const;
56#endif
57
58 void setCheckable(bool);
59 bool isCheckable() const;
60
61 bool isChecked() const;
62
63 void setDown(bool);
64 bool isDown() const;
65
66 void setAutoRepeat(bool);
67 bool autoRepeat() const;
68
69 void setAutoRepeatDelay(int autoRepeatDelay);
70 void setAutoRepeatDelay(std::chrono::milliseconds autoRepeatDelay);
71 int autoRepeatDelay() const;
72 std::chrono::milliseconds autoRepeatDelayAsDuration() const;
73
74 void setAutoRepeatInterval(int autoRepeatInterval);
75 void setAutoRepeatInterval(std::chrono::milliseconds autoRepeatInterval);
76 int autoRepeatInterval() const;
77 std::chrono::milliseconds autoRepeatIntervalAsDuration() const;
78
79 void setAutoExclusive(bool);
80 bool autoExclusive() const;
81
82#if QT_CONFIG(buttongroup)
83 QButtonGroup *group() const;
84#endif
85
86public Q_SLOTS:
87 void setIconSize(const QSize &size);
88 void animateClick();
89 void click();
90 void toggle();
91 void setChecked(bool);
92
93Q_SIGNALS:
94 void pressed();
95 void released();
96 void clicked(bool checked = false);
97 void toggled(bool checked);
98
99protected:
100 void paintEvent(QPaintEvent *e) override = 0;
101 virtual bool hitButton(const QPoint &pos) const;
102 virtual void checkStateSet();
103 virtual void nextCheckState();
104
105 bool event(QEvent *e) override;
106 void keyPressEvent(QKeyEvent *e) override;
107 void keyReleaseEvent(QKeyEvent *e) override;
108 void mousePressEvent(QMouseEvent *e) override;
109 void mouseReleaseEvent(QMouseEvent *e) override;
110 void mouseMoveEvent(QMouseEvent *e) override;
111 void focusInEvent(QFocusEvent *e) override;
112 void focusOutEvent(QFocusEvent *e) override;
113 void changeEvent(QEvent *e) override;
114 void timerEvent(QTimerEvent *e) override;
115
116
117protected:
118 QAbstractButton(QAbstractButtonPrivate &dd, QWidget* parent = nullptr);
119
120private:
121 Q_DECLARE_PRIVATE(QAbstractButton)
122 Q_DISABLE_COPY(QAbstractButton)
123 friend class QButtonGroup;
124};
125
126QT_END_NAMESPACE
127
128#endif // QABSTRACTBUTTON_H
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
friend class QWidget
Definition qpainter.h:432
static constexpr auto AUTO_REPEAT_INTERVAL
static QT_BEGIN_NAMESPACE constexpr auto AUTO_REPEAT_DELAY
Q_WIDGETS_EXPORT bool qt_tab_all_widgets()