Qt Utilities  5.6.0
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
clearspinbox.h
Go to the documentation of this file.
1 #ifndef WIDGETS_CLEARSPINBOX_H
2 #define WIDGETS_CLEARSPINBOX_H
3 
4 #include "./buttonoverlay.h"
5 
6 #include <QSpinBox>
7 #include <QLineEdit>
8 
9 QT_FORWARD_DECLARE_CLASS(QHBoxLayout)
10 
11 namespace Widgets {
12 
13 class IconButton;
14 
15 class QT_UTILITIES_EXPORT ClearSpinBox : public QSpinBox, public ButtonOverlay
16 {
17  Q_OBJECT
18  Q_PROPERTY(bool minimumHidden READ minimumHidden WRITE setMinimumHidden)
19  Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
20  Q_PROPERTY(bool isCleared READ isCleared)
21 
22 public:
23  explicit ClearSpinBox(QWidget *parent = nullptr);
24  ~ClearSpinBox();
25  bool minimumHidden() const;
26  void setMinimumHidden(bool value);
27  QString placeholderText() const;
28  void setPlaceholderText(const QString &placeholderText);
29  bool isCleared() const;
30 
31 protected:
32  int valueFromText(const QString &text) const;
33  QString textFromValue(int val) const;
34 
35 private Q_SLOTS:
36  void handleValueChanged(int value);
37  void handleClearButtonClicked();
38 
39 private:
40  bool m_minimumHidden;
41 
42 };
43 
47 inline bool ClearSpinBox::minimumHidden() const
48 {
49  return m_minimumHidden;
50 }
51 
55 inline void ClearSpinBox::setMinimumHidden(bool value)
56 {
57  m_minimumHidden = value;
58 }
59 
64 inline QString ClearSpinBox::placeholderText() const
65 {
66  return lineEdit()->placeholderText();
67 }
68 
73 inline void ClearSpinBox::setPlaceholderText(const QString &placeholderText)
74 {
75  lineEdit()->setPlaceholderText(placeholderText);
76 }
77 
78 }
79 
80 #endif // WIDGETS_CLEARSPINBOX_H
void setPlaceholderText(const QString &placeholderText)
Sets the placeholder text.
Definition: clearspinbox.h:73
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.
The ButtonOverlay class is used to display buttons on top of other widgets.
Definition: buttonoverlay.h:17
Provides a set of extended widgets such as ClearLineEdit and ClearComboBox.
Definition: buttonoverlay.h:13
A QSpinBox with an embedded button for clearing its contents and the ability to hide the minimum valu...
Definition: clearspinbox.h:15
#define text
QString placeholderText() const
void setMinimumHidden(bool value)
Sets whether the minimum value should be hidden.
Definition: clearspinbox.h:55