Debian Codegraph @

GUIWidgets/QtWidgets/QtPushButton.h

raw
1 /* Copyright (c) 2024, DyssolTEC GmbH.
2 * All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */
3
4 #pragma once
5
6 #include <QPushButton>
7
8 /**
9 * \brief Extends the standard QPushButton.
10 * \details If an icon is set, it will be aligned left, while the text will stay center aligned.
11 */
12 class CQtPushButton : public QPushButton
13 {
14 public:
15 explicit CQtPushButton(QWidget* _parent = nullptr);
16
17 /**
18 * \brief Returns current icon.
19 * \return Icon.
20 */
21 QIcon GetIcon();
22 /**
23 * \brief Sets new icon.
24 * \details Hides the parent function, so should be used with care from own code.
25 * But if the QPushButton is promoted to CQtPushButton in Qt Designer, this version will be properly called.
26 * \param _icon Icon.
27 */
28 void setIcon(const QIcon& _icon);
29 /**
30 * \brief Sets new icon size.
31 * \details Hides the parent function, so should be used with care from own code.
32 * But if the QPushButton is promoted to CQtPushButton in Qt Designer, this version will be properly called.
33 * \param _size
34 */
35 void setIconSize(const QSize& _size);
36
37 [[nodiscard]] QSize sizeHint() const override;
38
39 protected:
40 void paintEvent(QPaintEvent* _event) override;
41
42 private:
43 static constexpr int c_margin{ 5 }; /// Margin for icons.
44
45 QPixmap m_pixmap{}; /// Stores a scaled pixmap of the icon to be drawn.
46 QIcon m_icon{}; /// Current icon; it has to be stored for the case of the setIconSize event, to be able to rescale the pixmap without loosing picture quality.
47 };
48