1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-17 01:10:10 +00:00
OpenMW/apps/launcher/utils/lineedit.cpp

31 lines
932 B
C++
Raw Normal View History

#include "lineedit.hpp"
2013-02-14 10:20:47 +00:00
2022-09-22 18:26:05 +00:00
LineEdit::LineEdit(QWidget* parent)
2013-02-14 10:20:47 +00:00
: QLineEdit(parent)
{
setupClearButton();
}
void LineEdit::setupClearButton()
2013-02-14 10:20:47 +00:00
{
mClearButton = new QToolButton(this);
2023-01-06 19:01:50 +00:00
mClearButton->setIcon(QIcon::fromTheme("edit-clear"));
2013-02-14 10:20:47 +00:00
mClearButton->setCursor(Qt::ArrowCursor);
mClearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
mClearButton->hide();
connect(mClearButton, &QToolButton::clicked, this, &LineEdit::clear);
connect(this, &LineEdit::textChanged, this, &LineEdit::updateClearButton);
2013-02-14 10:20:47 +00:00
}
2022-09-22 18:26:05 +00:00
void LineEdit::resizeEvent(QResizeEvent*)
2013-02-14 10:20:47 +00:00
{
QSize sz = mClearButton->sizeHint();
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
2022-09-22 18:26:05 +00:00
mClearButton->move(rect().right() - frameWidth - sz.width(), (rect().bottom() + 1 - sz.height()) / 2);
2013-02-14 10:20:47 +00:00
}
void LineEdit::updateClearButton(const QString& text)
2013-02-14 10:20:47 +00:00
{
mClearButton->setVisible(!text.isEmpty());
}