qtutilities/widgets/clearlineedit.cpp

46 lines
872 B
C++
Raw Normal View History

2015-09-06 20:19:21 +02:00
#include "./clearlineedit.h"
2015-04-22 18:57:44 +02:00
namespace Widgets {
/*!
* \class Widgets::ClearLineEdit
* \brief A QLineEdit with an embedded button for clearing its contents.
*/
/*!
* \brief Constructs a clear line edit.
*/
2017-05-01 03:16:25 +02:00
ClearLineEdit::ClearLineEdit(QWidget *parent)
: QLineEdit(parent)
, ButtonOverlay(this)
2015-04-22 18:57:44 +02:00
{
ButtonOverlay::setClearButtonEnabled(true);
connect(this, &ClearLineEdit::textChanged, this, &ClearLineEdit::handleTextChanged);
}
/*!
* \brief Destroys the clear combo box.
*/
ClearLineEdit::~ClearLineEdit()
2017-05-01 03:16:25 +02:00
{
}
2015-04-22 18:57:44 +02:00
/*!
* \brief Updates the visibility of the clear button.
*/
void ClearLineEdit::handleTextChanged(const QString &text)
{
updateClearButtonVisibility(!text.isEmpty());
}
void ClearLineEdit::handleClearButtonClicked()
{
clear();
}
bool ClearLineEdit::isCleared() const
{
return text().isEmpty();
}
} // namespace Widgets