Mantid
Loading...
Searching...
No Matches
LineEditWithClear.cpp
Go to the documentation of this file.
1/****************************************************************************
2**
3** Copyright (c) 2007 Trolltech ASA <info@trolltech.com>
4**
5** Use, modification and distribution is allowed without limitation,
6** warranty, liability or support of any kind.
7**
8****************************************************************************/
9
11#include <QStyle>
12#include <QToolButton>
13
15
16LineEditWithClear::LineEditWithClear(QWidget *parent) : QLineEdit(parent) {
17 clearButton = new QToolButton(this);
18 QPixmap pixmap(QString::fromUtf8(":/fileclose.png"));
19 clearButton->setIcon(QIcon(pixmap));
20 clearButton->setIconSize(pixmap.size());
21 clearButton->setCursor(Qt::ArrowCursor);
22 clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
23 clearButton->hide();
24 connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
25 connect(this, SIGNAL(textChanged(const QString &)), this, SLOT(updateCloseButton(const QString &)));
26 int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
27 setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(clearButton->sizeHint().width() + frameWidth + 1));
28 QSize msz = minimumSizeHint();
29 setMinimumSize(qMax(msz.width(), clearButton->sizeHint().height() + frameWidth * 2 + 2),
30 qMax(msz.height(), clearButton->sizeHint().height() + frameWidth * 2 + 2));
31}
32
33void LineEditWithClear::resizeEvent(QResizeEvent * /*unused*/) {
34 QSize sz = clearButton->sizeHint();
35 int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
36 clearButton->move(rect().right() - frameWidth - sz.width(), (rect().bottom() + 1 - sz.height()) / 2);
37}
38
39void LineEditWithClear::updateCloseButton(const QString &text) { clearButton->setVisible(!text.isEmpty()); }
40} // namespace MantidQt::MantidWidgets
double bottom
Definition: LineProfile.cpp:79
double right
Definition: LineProfile.cpp:81
void resizeEvent(QResizeEvent *) override