File indexing completed on 2026-09-22 09:04:32
0001
0002
0003
0004
0005 #ifndef QABSTRACTBUTTON_H
0006 #define QABSTRACTBUTTON_H
0007
0008 #include <QtWidgets/qtwidgetsglobal.h>
0009 #include <QtGui/qicon.h>
0010 #if QT_CONFIG(shortcut)
0011 # include <QtGui/qkeysequence.h>
0012 #endif
0013 #include <QtWidgets/qwidget.h>
0014
0015 QT_REQUIRE_CONFIG(abstractbutton);
0016
0017 QT_BEGIN_NAMESPACE
0018
0019
0020 class QButtonGroup;
0021 class QAbstractButtonPrivate;
0022
0023 class Q_WIDGETS_EXPORT QAbstractButton : public QWidget
0024 {
0025 Q_OBJECT
0026
0027 Q_PROPERTY(QString text READ text WRITE setText)
0028 Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
0029 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
0030 #ifndef QT_NO_SHORTCUT
0031 Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)
0032 #endif
0033 Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable)
0034 Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled USER true)
0035 Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat)
0036 Q_PROPERTY(bool autoExclusive READ autoExclusive WRITE setAutoExclusive)
0037 Q_PROPERTY(int autoRepeatDelay READ autoRepeatDelay WRITE setAutoRepeatDelay)
0038 Q_PROPERTY(int autoRepeatInterval READ autoRepeatInterval WRITE setAutoRepeatInterval)
0039 Q_PROPERTY(bool down READ isDown WRITE setDown DESIGNABLE false)
0040
0041 public:
0042 explicit QAbstractButton(QWidget *parent = nullptr);
0043 ~QAbstractButton();
0044
0045 void setText(const QString &text);
0046 QString text() const;
0047
0048 void setIcon(const QIcon &icon);
0049 QIcon icon() const;
0050
0051 QSize iconSize() const;
0052
0053 #ifndef QT_NO_SHORTCUT
0054 void setShortcut(const QKeySequence &key);
0055 QKeySequence shortcut() const;
0056 #endif
0057
0058 void setCheckable(bool);
0059 bool isCheckable() const;
0060
0061 bool isChecked() const;
0062
0063 void setDown(bool);
0064 bool isDown() const;
0065
0066 void setAutoRepeat(bool);
0067 bool autoRepeat() const;
0068
0069 void setAutoRepeatDelay(int);
0070 int autoRepeatDelay() const;
0071
0072 void setAutoRepeatInterval(int);
0073 int autoRepeatInterval() const;
0074
0075 void setAutoExclusive(bool);
0076 bool autoExclusive() const;
0077
0078 #if QT_CONFIG(buttongroup)
0079 QButtonGroup *group() const;
0080 #endif
0081
0082 public Q_SLOTS:
0083 void setIconSize(const QSize &size);
0084 void animateClick();
0085 void click();
0086 void toggle();
0087 void setChecked(bool);
0088
0089 Q_SIGNALS:
0090 void pressed();
0091 void released();
0092 void clicked(bool checked = false);
0093 void toggled(bool checked);
0094
0095 protected:
0096 void paintEvent(QPaintEvent *e) override = 0;
0097 virtual bool hitButton(const QPoint &pos) const;
0098 virtual void checkStateSet();
0099 virtual void nextCheckState();
0100
0101 bool event(QEvent *e) override;
0102 void keyPressEvent(QKeyEvent *e) override;
0103 void keyReleaseEvent(QKeyEvent *e) override;
0104 void mousePressEvent(QMouseEvent *e) override;
0105 void mouseReleaseEvent(QMouseEvent *e) override;
0106 void mouseMoveEvent(QMouseEvent *e) override;
0107 void focusInEvent(QFocusEvent *e) override;
0108 void focusOutEvent(QFocusEvent *e) override;
0109 void changeEvent(QEvent *e) override;
0110 void timerEvent(QTimerEvent *e) override;
0111
0112
0113 protected:
0114 QAbstractButton(QAbstractButtonPrivate &dd, QWidget* parent = nullptr);
0115
0116 private:
0117 Q_DECLARE_PRIVATE(QAbstractButton)
0118 Q_DISABLE_COPY(QAbstractButton)
0119 friend class QButtonGroup;
0120 };
0121
0122 QT_END_NAMESPACE
0123
0124 #endif