KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
pushbutton.h
1#ifndef PUSHBUTTON_H
2#define PUSHBUTTON_H
3
4#include <QPushButton>
5#include <Kanoop/gui/libkanoopgui.h>
6
7/**
8 * @brief QPushButton subclass with stylesheet-based color and font customization.
9 *
10 * PushButton extends QPushButton to provide programmatic control over foreground,
11 * background, hover, pressed, and disabled state colors via Qt stylesheets.
12 * It also offers convenience methods for font size, weight, and style changes.
13 */
14class LIBKANOOPGUI_EXPORT PushButton : public QPushButton
15{
16 Q_OBJECT
17
18 /** @brief The current foreground (text) color of the button. */
19 Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor) // clazy:exclude=qproperty-without-notify
20 /** @brief The current background color of the button. */
21 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) // clazy:exclude=qproperty-without-notify
22
23public:
24 /** @brief Construct a PushButton with an optional parent widget. */
25 explicit PushButton(QWidget *parent = nullptr);
26 /** @brief Construct a PushButton with the given text and optional parent widget. */
27 explicit PushButton(const QString &text, QWidget *parent = nullptr);
28 /** @brief Construct a PushButton with the given icon, text, and optional parent widget. */
29 PushButton(const QIcon& icon, const QString &text, QWidget *parent = nullptr);
30
31 /** @brief Set the font point size. */
32 void setFontPointSize(int size);
33 /** @brief Set the font pixel size. */
34 void setFontPixelSize(int size);
35 /** @brief Set the font bold state. */
36 void setBold(bool bold);
37 /** @brief Set the font italic state. */
38 void setItalic(bool italic);
39
40 /** @brief Get the current foreground color. */
41 QColor foregroundColor() const { return _foregroundColor; }
42 /** @brief Get the current background color. */
43 QColor backgroundColor() const { return _backgroundColor; }
44
45 /** @brief Set the border radius in pixels. */
46 void setBorderRadius(int radius);
47
48 /** @brief Set the foreground color when the mouse hovers over the button. */
49 void setHoverForegroundColor(const QColor& color);
50 /** @brief Set the background color when the mouse hovers over the button. */
51 void setHoverBackgroundColor(const QColor& color);
52 /** @brief Set the foreground color when the button is pressed. */
53 void setPressedForegroundColor(const QColor& color);
54 /** @brief Set the background color when the button is pressed. */
55 void setPressedBackgroundColor(const QColor& color);
56 /** @brief Set the foreground color when the button is disabled. */
57 void setDisabledForegroundColor(const QColor& color);
58 /** @brief Set the background color when the button is disabled. */
59 void setDisabledBackgroundColor(const QColor& color);
60
61public slots:
62 /** @brief Set the foreground (text) color and rebuild the stylesheet. */
63 void setForegroundColor(const QColor& color);
64 /** @brief Set the background color and rebuild the stylesheet. */
65 void setBackgroundColor(const QColor& color);
66 /** @brief Reset the foreground color to the palette default. */
68 /** @brief Reset the background color to the palette default. */
70
71private:
72 void commonInit();
73 void makeStyleSheet();
74
75 QColor _foregroundColor;
76 QColor _backgroundColor;
77 QColor _hoverForegroundColor; // invalid QColor() = not set
78 QColor _hoverBackgroundColor;
79 QColor _pressedForegroundColor;
80 QColor _pressedBackgroundColor;
81 QColor _disabledForegroundColor;
82 QColor _disabledBackgroundColor;
83 int _borderRadius = 0;
84};
85
86#endif // PUSHBUTTON_H
QPushButton subclass with stylesheet-based color and font customization.
Definition pushbutton.h:15
void setBorderRadius(int radius)
Set the border radius in pixels.
void setDisabledForegroundColor(const QColor &color)
Set the foreground color when the button is disabled.
void setHoverBackgroundColor(const QColor &color)
Set the background color when the mouse hovers over the button.
QColor backgroundColor() const
Get the current background color.
Definition pushbutton.h:43
void setBackgroundColor(const QColor &color)
Set the background color and rebuild the stylesheet.
void setPressedForegroundColor(const QColor &color)
Set the foreground color when the button is pressed.
void setDefaultBackgroundColor()
Reset the background color to the palette default.
void setDisabledBackgroundColor(const QColor &color)
Set the background color when the button is disabled.
void setForegroundColor(const QColor &color)
Set the foreground (text) color and rebuild the stylesheet.
void setPressedBackgroundColor(const QColor &color)
Set the background color when the button is pressed.
void setDefaultForegroundColor()
Reset the foreground color to the palette default.
void setHoverForegroundColor(const QColor &color)
Set the foreground color when the mouse hovers over the button.