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
clearcombobox.cpp
Go to the documentation of this file.
1#include "./clearcombobox.h"
2
3#include <QHBoxLayout>
4#include <QStyle>
5#include <QStyleOptionComboBox>
6
7namespace QtUtilities {
8
13
15static inline auto *getComboBoxLineEdit(QComboBox *comboBox)
16{
17 comboBox->setEditable(true);
18 return comboBox->lineEdit();
19}
21
27 : QComboBox(parent)
28 , ButtonOverlay(this, getComboBoxLineEdit(this))
29{
31}
32
39
43void ClearComboBox::handleTextChanged(const QString &text)
44{
46}
47
49{
50 clearEditText();
51}
52
54{
55 const QStyle *const s = style();
56 QStyleOptionComboBox opt;
57 opt.initFrom(this);
58 setContentsMarginsFromEditFieldRectAndFrameWidth(
59 s->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxEditField, this), s->pixelMetric(QStyle::PM_ComboBoxFrameWidth, &opt, this));
60 connect(this, &ClearComboBox::currentTextChanged, this, &ClearComboBox::handleTextChanged);
61}
62
64{
65 return currentText().isEmpty();
66}
67} // 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.
~ClearComboBox() override
Destroys the clear combo box.
bool isCleared() const override
Returns whether the related widget is cleared.
#define text