KWidgetsAddons

kcolorbutton.h
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1997 Martin Jones <mjones@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KCOLORBUTTON_H
9#define KCOLORBUTTON_H
10
11#include <kwidgetsaddons_export.h>
12
13#include <QPushButton>
14#include <memory>
15
16class KColorButtonPrivate;
17/**
18 * @class KColorButton kcolorbutton.h KColorButton
19 *
20 * @short A pushbutton to display or allow user selection of a color.
21 *
22 * This widget can be used to display or allow user selection of a color.
23 *
24 * \image html kcolorbutton.png "KColorButton Widget"
25 *
26 * @see QColorDialog
27 */
28class KWIDGETSADDONS_EXPORT KColorButton : public QPushButton
29{
31 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY changed USER true)
32 Q_PROPERTY(QColor defaultColor READ defaultColor WRITE setDefaultColor)
33 Q_PROPERTY(bool alphaChannelEnabled READ isAlphaChannelEnabled WRITE setAlphaChannelEnabled)
34
35public:
36 /**
37 * Creates a color button.
38 */
39 explicit KColorButton(QWidget *parent = nullptr);
40
41 /**
42 * Creates a color button with an initial color @p c.
43 */
44 explicit KColorButton(const QColor &c, QWidget *parent = nullptr);
45
46 /**
47 * Creates a color button with an initial color @p c and default color @p defaultColor.
48 */
49 KColorButton(const QColor &c, const QColor &defaultColor, QWidget *parent = nullptr);
50
51 ~KColorButton() override;
52
53 /**
54 * Returns the currently chosen color.
55 */
56 QColor color() const;
57
58 /**
59 * Sets the current color to @p c.
60 */
61 void setColor(const QColor &c);
62
63 /**
64 * When set to true, allow the user to change the alpha component
65 * of the color. The default value is false.
66 * @since 4.5
67 */
68 void setAlphaChannelEnabled(bool alpha);
69
70 /**
71 * Returns true if the user is allowed to change the alpha component.
72 * @since 4.5
73 */
74 bool isAlphaChannelEnabled() const;
75
76 /**
77 * Returns the default color or an invalid color
78 * if no default color is set.
79 */
80 QColor defaultColor() const;
81
82 /**
83 * Sets the default color to @p c.
84 */
85 void setDefaultColor(const QColor &c);
86
87 QSize sizeHint() const override;
88 QSize minimumSizeHint() const override;
89
91 /**
92 * Emitted when the color of the widget
93 * is changed, either with setColor() or via user selection.
94 */
95 void changed(const QColor &newColor);
96
97protected:
98 void paintEvent(QPaintEvent *pe) override;
99 void dragEnterEvent(QDragEnterEvent *) override;
100 void dropEvent(QDropEvent *) override;
101 void mousePressEvent(QMouseEvent *e) override;
102 void mouseMoveEvent(QMouseEvent *e) override;
103 void keyPressEvent(QKeyEvent *e) override;
104
105private:
106 std::unique_ptr<class KColorButtonPrivate> const d;
107};
108
109#endif
void setDefaultColor(const QColor &c)
Sets the default color to c.
KColorButton(QWidget *parent=nullptr)
Creates a color button.
void changed(const QColor &newColor)
Emitted when the color of the widget is changed, either with setColor() or via user selection.
void setColor(const QColor &c)
Sets the current color to c.
bool isAlphaChannelEnabled() const
Returns true if the user is allowed to change the alpha component.
void setAlphaChannelEnabled(bool alpha)
When set to true, allow the user to change the alpha component of the color.
virtual void mousePressEvent(QMouseEvent *e) override
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
QPushButton(QWidget *parent)
virtual void keyPressEvent(QKeyEvent *e) override
virtual QSize minimumSizeHint() const const override
virtual void mouseMoveEvent(QMouseEvent *e) override
virtual void paintEvent(QPaintEvent *) override
virtual QSize sizeHint() const const override
QWidget(QWidget *parent, Qt::WindowFlags f)
virtual void dragEnterEvent(QDragEnterEvent *event)
virtual void dropEvent(QDropEvent *event)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 21 2025 11:52:02 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.