Qt 4.8
qabstractbutton.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QABSTRACTBUTTON_H
43 #define QABSTRACTBUTTON_H
44 
45 #include <QtGui/qicon.h>
46 #include <QtGui/qkeysequence.h>
47 #include <QtGui/qwidget.h>
48 
50 
52 
53 QT_MODULE(Gui)
54 
55 class QButtonGroup;
57 
59 {
60  Q_OBJECT
61 
65 #ifndef QT_NO_SHORTCUT
67 #endif
68  bool checkable;
69  bool checked;
70  bool autoRepeat;
74  bool down;
75 
76 public:
77  explicit QAbstractButton(QWidget* parent=0);
78  ~QAbstractButton();
79 
80  void setText(const QString &text);
81  QString text() const;
82 
83  void setIcon(const QIcon &icon);
84  QIcon icon() const;
85 
86  QSize iconSize() const;
87 
88 #ifndef QT_NO_SHORTCUT
89  void setShortcut(const QKeySequence &key);
90  QKeySequence shortcut() const;
91 #endif
92 
93  void setCheckable(bool);
94  bool isCheckable() const;
95 
96  bool isChecked() const;
97 
98  void setDown(bool);
99  bool isDown() const;
100 
101  void setAutoRepeat(bool);
102  bool autoRepeat() const;
103 
104  void setAutoRepeatDelay(int);
105  int autoRepeatDelay() const;
106 
107  void setAutoRepeatInterval(int);
108  int autoRepeatInterval() const;
109 
110  void setAutoExclusive(bool);
111  bool autoExclusive() const;
112 
113 #ifndef QT_NO_BUTTONGROUP
114  QButtonGroup *group() const;
115 #endif
116 
117 public Q_SLOTS:
118  void setIconSize(const QSize &size);
119  void animateClick(int msec = 100);
120  void click();
121  void toggle();
122  void setChecked(bool);
123 
124 Q_SIGNALS:
125  void pressed();
126  void released();
127  void clicked(bool checked = false);
128  void toggled(bool checked);
129 
130 protected:
131  virtual void paintEvent(QPaintEvent *e) = 0;
132  virtual bool hitButton(const QPoint &pos) const;
133  virtual void checkStateSet();
134  virtual void nextCheckState();
135 
136  bool event(QEvent *e);
137  void keyPressEvent(QKeyEvent *e);
138  void keyReleaseEvent(QKeyEvent *e);
139  void mousePressEvent(QMouseEvent *e);
141  void mouseMoveEvent(QMouseEvent *e);
142  void focusInEvent(QFocusEvent *e);
143  void focusOutEvent(QFocusEvent *e);
144  void changeEvent(QEvent *e);
145  void timerEvent(QTimerEvent *e);
146 
147 public:
148 #ifdef QT3_SUPPORT
149  QT3_SUPPORT_CONSTRUCTOR QAbstractButton(QWidget *parent, const char *name, Qt::WindowFlags f=0);
150  inline QT3_SUPPORT bool isOn() const { return isChecked(); }
151  inline QT3_SUPPORT const QPixmap *pixmap() const { return 0; } // help styles compile
152  inline QT3_SUPPORT void setPixmap( const QPixmap &p ) {
153  setIcon(QIcon(p));
154  setIconSize(p.size());
155  }
156  QT3_SUPPORT QIcon *iconSet() const;
157  inline QT3_SUPPORT void setIconSet(const QIcon &icon) { setIcon(icon); }
158  inline QT3_SUPPORT bool isToggleButton() const { return isCheckable(); }
159  inline QT3_SUPPORT void setToggleButton(bool b) { setCheckable(b); }
160  inline QT3_SUPPORT void setAccel(const QKeySequence &key) { setShortcut(key); }
161  inline QT3_SUPPORT QKeySequence accel() const { return shortcut(); }
162 
163 public Q_SLOTS:
164  inline QT_MOC_COMPAT void setOn(bool b) { setChecked(b); }
165 #endif
166 
167 protected:
169 
170 private:
174 };
175 
177 
179 
180 #endif // QABSTRACTBUTTON_H
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
#define QT_MOC_COMPAT
Definition: qglobal.h:1128
The QKeyEvent class describes a key event.
Definition: qevent.h:224
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
bool autoRepeat
whether autoRepeat is enabled
virtual void mouseReleaseEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
Definition: qwidget.cpp:9286
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
virtual void mousePressEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition: qwidget.cpp:9261
virtual void timerEvent(QTimerEvent *)
This event handler can be reimplemented in a subclass to receive timer events for the object...
Definition: qobject.cpp:1294
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int autoRepeatInterval
the interval of auto-repetition
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
virtual void keyReleaseEvent(QKeyEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive key release events...
Definition: qwidget.cpp:9407
#define Q_SLOTS
Definition: qobjectdefs.h:71
QString text
the text shown on the button
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_SIGNALS
Definition: qobjectdefs.h:72
QSize iconSize
the icon size used for this button.
virtual void focusOutEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition: qwidget.cpp:9457
virtual void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
Definition: qwidget.cpp:9548
bool checked
whether the button is checked
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const char * name
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
virtual void keyPressEvent(QKeyEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
Definition: qwidget.cpp:9375
#define Q_OBJECT
Definition: qobjectdefs.h:157
bool checkable
whether the button is checkable
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
QIcon icon
the icon shown on the button
bool down
whether the button is pressed down
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:72
int autoRepeatDelay
the initial delay of auto-repetition
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
QKeySequence shortcut
the mnemonic associated with the button
bool autoExclusive
whether auto-exclusivity is enabled
int key
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
virtual void mouseMoveEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition: qwidget.cpp:9239
#define class
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
The QButtonGroup class provides a container to organize groups of button widgets. ...
Definition: qbuttongroup.h:59
virtual void focusInEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition: qwidget.cpp:9431
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
#define text
Definition: qobjectdefs.h:80
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60