1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-29 03:19:44 +00:00
OpenMW/apps/launcher/utils/lineedit.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
932 B
C++
Raw Normal View History

#include "lineedit.hpp"
2013-02-14 10:20:47 +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
}
void LineEdit::resizeEvent(QResizeEvent*)
2013-02-14 10:20:47 +00:00
{
QSize sz = mClearButton->sizeHint();
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
mClearButton->move(rect().right() - frameWidth - sz.width(), (rect().bottom() + 1 - sz.height()) / 2);
}
void LineEdit::updateClearButton(const QString& text)
2013-02-14 10:20:47 +00:00
{
mClearButton->setVisible(!text.isEmpty());
}