Qt Utilities  6.4.1
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
clearlineedit.cpp
Go to the documentation of this file.
1 #include "./clearlineedit.h"
2 
3 #include <QStyle>
4 #include <QStyleOptionFrame>
5 
6 namespace QtUtilities {
7 
17  : QLineEdit(parent)
18  , ButtonOverlay(this, this)
19 {
21 }
22 
27 {
28 }
29 
33 void ClearLineEdit::handleTextChanged(const QString &text)
34 {
36 }
37 
38 void ClearLineEdit::handleClearButtonClicked()
39 {
40  clear();
41 }
42 
43 void ClearLineEdit::handleCustomLayoutCreated()
44 {
45  const QStyle *const s = style();
46  QStyleOptionFrame opt;
47  opt.initFrom(this);
48  setContentsMarginsFromEditFieldRectAndFrameWidth(s->subElementRect(QStyle::SE_LineEditContents, &opt, this),
49  s->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, m_widget), s->pixelMetric(QStyle::PM_LayoutVerticalSpacing, &opt, m_widget));
50  connect(this, &ClearLineEdit::textChanged, this, &ClearLineEdit::handleTextChanged);
51 }
52 
54 {
55  return text().isEmpty();
56 }
57 } // namespace QtUtilities
The ButtonOverlay class is used to display buttons on top of other widgets.
Definition: buttonoverlay.h:25
void updateClearButtonVisibility(bool visible)
Updates the visibility of the clear button.
void setClearButtonEnabled(bool enabled)
Sets whether the clear button is enabled.
~ClearLineEdit() override
Destroys the clear combo box.
bool isCleared() const override
Returns whether the related widget is cleared.
#define text