1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-08 09:37:53 +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.

34 lines
1023 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);
QPixmap pixmap(":images/clear.png");
mClearButton->setIcon(QIcon(pixmap));
mClearButton->setIconSize(pixmap.size());
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());
}