31 clearButton(new QToolButton(this))
33 QIcon icon = QIcon::fromTheme(
"edit-clear", QIcon(
":/icon/dialog-close.ico"));
34 clearButton->setIcon(icon);
35 clearButton->setCursor(Qt::ArrowCursor);
36 clearButton->setStyleSheet(
"QToolButton { border: none; padding: 0px; }");
39 int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
40 setStyleSheet(QString(
"QLineEdit { padding-right: %1px; } ").arg(clearButton->sizeHint().width() + frameWidth + 1));
41 QSize minSize = minimumSizeHint();
42 setMinimumSize(qMax(minSize.width(), clearButton->sizeHint().height() + frameWidth * 2 + 2), qMax(minSize.height(), clearButton->sizeHint().height() + frameWidth * 2 + 2));
44 connect(clearButton, SIGNAL(clicked()),
this, SLOT(clear()));
45 connect(
this, SIGNAL(textChanged(
const QString&)),
this, SLOT(updateClearButton(
const QString&)));
50 QSize size = clearButton->sizeHint();
51 int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
52 clearButton->move(rect().right() - frameWidth - size.width(),
53 (rect().bottom() + 1 - size.height()) / 2);
56 void gui::ClearableLineEdit::updateClearButton(
const QString& text)
58 clearButton->setVisible(!text.isEmpty());