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