Qt Utilities: widgets/iconbutton.h Source File

Qt Utilities 6.22.1 Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models

Loading...
Searching...
No Matches
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 <QAction>
8#include <QPixmap>
9#include <QSize>
10
11#include <cstdint>
12
13namespace QtUtilities {
14
15 class QT_UTILITIES_EXPORT IconButton : public QAbstractButton {
16 Q_OBJECT
17 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
18
19public:
20 explicit IconButton(QWidget *parent = nullptr);
21 ~IconButton() override;
22
23 static IconButton *fromAction(QAction *action, std::uintptr_t id = 0);
24 const QPixmap &pixmap() const;
25 void setPixmap(const QPixmap &pixmap);
26 QSize sizeHint() const override;
27
28 static constexpr auto defaultPixmapSize = QSize(16, 16);
29
30protected:
31 void paintEvent(QPaintEvent *event) override;
32 void keyPressEvent(QKeyEvent *event) override;
33 void keyReleaseEvent(QKeyEvent *event) override;
34
35private Q_SLOTS:
36 void assignDataFromActionChangedSignal();
37 void assignDataFromAction(const QAction *action);
38
39private:
40 QPixmap m_pixmap;
41};
42
46 inline const QPixmap &IconButton::pixmap() const
47{
48 return m_pixmap;
49}
50
54 inline void IconButton::setPixmap(const QPixmap &pixmap)
55{
56 m_pixmap = pixmap;
57 update();
58}
59} // namespace QtUtilities
60
61#endif // WIDGETS_ICONBUTTON_H
QtUtilities::IconButton::setPixmap
void setPixmap(const QPixmap &pixmap)
Sets the pixmap.
Definition iconbutton.h:54
QtUtilities::IconButton::defaultPixmapSize
static constexpr auto defaultPixmapSize
Definition iconbutton.h:28
QtUtilities::IconButton::IconButton
IconButton(QWidget *parent=nullptr)
Constructs an icon button.
Definition iconbutton.cpp:22
QtUtilities::IconButton::pixmap
QPixmap pixmap
Definition iconbutton.h:17
QtUtilities::IconButton::paintEvent
void paintEvent(QPaintEvent *event) override
Definition iconbutton.cpp:86
QtUtilities::IconButton::keyPressEvent
void keyPressEvent(QKeyEvent *event) override
Definition iconbutton.cpp:110
QtUtilities::IconButton::fromAction
static IconButton * fromAction(QAction *action, std::uintptr_t id=0)
Creates an IconButton for the specified action.
Definition iconbutton.cpp:41
QtUtilities::IconButton::sizeHint
QSize sizeHint() const override
Definition iconbutton.cpp:76
QtUtilities::IconButton::keyReleaseEvent
void keyReleaseEvent(QKeyEvent *event) override
Definition iconbutton.cpp:119
global.h
QT_UTILITIES_EXPORT
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.
Definition global.h:14
QtUtilities
!
Definition trylocker.h:8