KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
checkbox.h
1#ifndef CHECKBOX_H
2#define CHECKBOX_H
3
4#include <QCheckBox>
5#include <Kanoop/gui/libkanoopgui.h>
6
7/**
8 * @brief QCheckBox subclass with an optional read-only mode.
9 *
10 * CheckBox exposes a readOnly property. When set, mouse press events are
11 * suppressed so that the check state cannot be changed by the user.
12 */
13class LIBKANOOPGUI_EXPORT CheckBox : public QCheckBox
14{
15 /** @brief Whether the checkbox ignores user mouse presses. */
16 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) // clazy:exclude=qproperty-without-notify
17 Q_OBJECT
18public:
19 /**
20 * @brief Construct with an optional parent.
21 * @param parent Optional QWidget parent
22 */
23 explicit CheckBox(QWidget *parent = nullptr);
24
25 /**
26 * @brief Construct with initial label text.
27 * @param text Checkbox label
28 * @param parent Optional QWidget parent
29 */
30 explicit CheckBox(const QString &text, QWidget *parent = nullptr);
31
32 /**
33 * @brief Return whether the checkbox is read-only.
34 * @return true if user interaction is suppressed
35 */
36 bool isReadOnly() const { return _readOnly; }
37
38public slots:
39 /**
40 * @brief Enable or disable the read-only mode.
41 * @param value true to prevent user changes
42 */
43 void setReadOnly(bool value) { _readOnly = value; }
44
45private:
46 virtual void mousePressEvent(QMouseEvent* event) override;
47
48private:
49 bool _readOnly = false;
50};
51
52#endif // CHECKBOX_H
QCheckBox subclass with an optional read-only mode.
Definition checkbox.h:14
void setReadOnly(bool value)
Enable or disable the read-only mode.
Definition checkbox.h:43
bool isReadOnly() const
Return whether the checkbox is read-only.
Definition checkbox.h:36
CheckBox(const QString &text, QWidget *parent=nullptr)
Construct with initial label text.
CheckBox(QWidget *parent=nullptr)
Construct with an optional parent.