Qt Utilities  5.6.0
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
iconbutton.h
Go to the documentation of this file.
1 #ifndef WIDGETS_ICONBUTTON_H
2 #define WIDGETS_ICONBUTTON_H
3 
4 #include "../global.h"
5 
6 #include <QAbstractButton>
7 #include <QPixmap>
8 
9 namespace Widgets {
10 
11 class QT_UTILITIES_EXPORT IconButton : public QAbstractButton
12 {
13  Q_OBJECT
14  Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
15 
16 public:
17  explicit IconButton(QWidget *parent = nullptr);
18  ~IconButton();
19 
20  const QPixmap &pixmap() const;
21  void setPixmap(const QPixmap &pixmap);
22  QSize sizeHint() const;
23 
24 protected:
25  void paintEvent(QPaintEvent *event);
26  void keyPressEvent(QKeyEvent *event);
27  void keyReleaseEvent(QKeyEvent *event);
28 
29 private:
30  QPixmap m_pixmap;
31 };
32 
36 inline const QPixmap &IconButton::pixmap() const
37 {
38  return m_pixmap;
39 }
40 
44 inline void IconButton::setPixmap(const QPixmap &pixmap)
45 {
46  m_pixmap = pixmap;
47  update();
48 }
49 
50 }
51 
52 #endif // WIDGETS_ICONBUTTON_H
A simple QAbstractButton implementation displaying a QPixmap.
Definition: iconbutton.h:11
void setPixmap(const QPixmap &pixmap)
Sets the pixmap.
Definition: iconbutton.h:44
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.
Provides a set of extended widgets such as ClearLineEdit and ClearComboBox.
Definition: buttonoverlay.h:13
const QPixmap & pixmap() const