Qt Utilities: widgets/clearlineedit.cpp Source File

Qt Utilities 6.21.3 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
16 ClearLineEdit::ClearLineEdit(QWidget *parent)
17 : QLineEdit(parent)
18 , ButtonOverlay(this, this)
19{
20 ButtonOverlay::setClearButtonEnabled(true);
21}
22
26ClearLineEdit::~ClearLineEdit()
27{
28}
29
33void ClearLineEdit::handleTextChanged(const QString &text)
34{
35 updateClearButtonVisibility(!text.isEmpty());
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
53 bool ClearLineEdit::isCleared() const
54{
55 return text().isEmpty();
56}
57} // namespace QtUtilities
QtUtilities::ButtonOverlay::updateClearButtonVisibility
void updateClearButtonVisibility(bool visible)
Updates the visibility of the clear button.
Definition buttonoverlay.cpp:283
QtUtilities::ButtonOverlay::handleCustomLayoutCreated
virtual void handleCustomLayoutCreated()
Applies additional handling when the button layout has been created.
Definition buttonoverlay.cpp:305
QtUtilities::ButtonOverlay::ButtonOverlay
ButtonOverlay(QWidget *widget)
Constructs a button overlay for the specified widget.
Definition buttonoverlay.cpp:49
QtUtilities::ButtonOverlay::handleClearButtonClicked
virtual void handleClearButtonClicked()
Clears the related widget.
Definition buttonoverlay.cpp:295
QtUtilities::ButtonOverlay::ClearLineEdit
friend class ClearLineEdit
Definition buttonoverlay.h:30
QtUtilities::ButtonOverlay::setClearButtonEnabled
void setClearButtonEnabled(bool enabled)
Sets whether the clear button is enabled.
Definition buttonoverlay.cpp:125
QtUtilities::ClearLineEdit::~ClearLineEdit
~ClearLineEdit() override
Destroys the clear combo box.
Definition clearlineedit.cpp:26
QtUtilities::ClearLineEdit::isCleared
bool isCleared() const override
Returns whether the related widget is cleared.
Definition clearlineedit.cpp:53
clearlineedit.h
QtUtilities
!
Definition trylocker.h:8
text
#define text
Definition xmlparsermacros.h:18