Qt Utilities  5.7.1
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 <QLineEdit>
7 #include <QSpinBox>
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  Q_OBJECT
17  Q_PROPERTY(bool minimumHidden READ minimumHidden WRITE setMinimumHidden)
18  Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
19  Q_PROPERTY(bool isCleared READ isCleared)
20 
21 public:
22  explicit ClearSpinBox(QWidget *parent = nullptr);
23  ~ClearSpinBox();
24  bool minimumHidden() const;
25  void setMinimumHidden(bool value);
26  QString placeholderText() const;
27  void setPlaceholderText(const QString &placeholderText);
28  bool isCleared() const;
29 
30 protected:
31  int valueFromText(const QString &text) const;
32  QString textFromValue(int val) const;
33 
34 private Q_SLOTS:
35  void handleValueChanged(int value);
36  void handleClearButtonClicked();
37 
38 private:
39  bool m_minimumHidden;
40 };
41 
45 inline bool ClearSpinBox::minimumHidden() const
46 {
47  return m_minimumHidden;
48 }
49 
53 inline void ClearSpinBox::setMinimumHidden(bool value)
54 {
55  m_minimumHidden = value;
56 }
57 
62 inline QString ClearSpinBox::placeholderText() const
63 {
64  return lineEdit()->placeholderText();
65 }
66 
71 inline void ClearSpinBox::setPlaceholderText(const QString &placeholderText)
72 {
73  lineEdit()->setPlaceholderText(placeholderText);
74 }
75 }
76 
77 #endif // WIDGETS_CLEARSPINBOX_H
void setPlaceholderText(const QString &placeholderText)
Sets the placeholder text.
Definition: clearspinbox.h:71
#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:53