Qt Utilities 6.12.0
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
Loading...
Searching...
No Matches
clearlineedit.cpp
Go to the documentation of this file.
1#include "./clearlineedit.h"
2
3#include <QStyle>
4#include <QStyleOptionFrame>
5
6namespace QtUtilities {
7
17 : QLineEdit(parent)
18 , ButtonOverlay(this, this)
19{
21}
22
27{
28}
29
33void ClearLineEdit::handleTextChanged(const QString &text)
34{
36}
37
38void ClearLineEdit::handleClearButtonClicked()
39{
40 clear();
41}
42
43void 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