Qt Utilities 6.18.1
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
12
17 : QLineEdit(parent)
18 , ButtonOverlay(this, this)
19{
21}
22
29
33void ClearLineEdit::handleTextChanged(const QString &text)
34{
36}
37
39{
40 clear();
41}
42
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
void updateClearButtonVisibility(bool visible)
Updates the visibility of the clear button.
virtual void handleCustomLayoutCreated()
Applies additional handling when the button layout has been created.
ButtonOverlay(QWidget *widget)
Constructs a button overlay for the specified widget.
virtual void handleClearButtonClicked()
Clears the related widget.
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