Browse Source

Fix toolbar resizing when m_searchFilter appears/disappears. Closes #5120.

adaptive-webui-19844
Chocobo1 9 years ago
parent
commit
c52a964a8a
  1. 20
      src/gui/lineedit/src/lineedit.cpp

20
src/gui/lineedit/src/lineedit.cpp

@ -16,17 +16,15 @@
LineEdit::LineEdit(QWidget *parent) LineEdit::LineEdit(QWidget *parent)
: QLineEdit(parent) : QLineEdit(parent)
{ {
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
QPixmap pixmap1(":/lineeditimages/search.png"); QPixmap pixmap1(":/lineeditimages/search.png");
searchButton = new QToolButton(this); searchButton = new QToolButton(this);
searchButton->setIcon(QIcon(pixmap1)); searchButton->setIcon(QIcon(pixmap1));
searchButton->setIconSize(pixmap1.size()); searchButton->setIconSize(pixmap1.size());
searchButton->setCursor(Qt::ArrowCursor); searchButton->setCursor(Qt::ArrowCursor);
searchButton->setStyleSheet("QToolButton { border: none; padding: 2px; }"); searchButton->setStyleSheet("QToolButton { border: none; padding: 2px; }");
QSize searchButtonHint = searchButton->sizeHint();
int clearButtonSizeHintWidth = 0; QSize clearButtonHint(0, 0);
int clearButtonSizeHintHeight = 0;
#ifndef QBT_USES_QT5 #ifndef QBT_USES_QT5
QPixmap pixmap2(":/lineeditimages/clear_left.png"); QPixmap pixmap2(":/lineeditimages/clear_left.png");
clearButton = new QToolButton(this); clearButton = new QToolButton(this);
@ -39,17 +37,17 @@ LineEdit::LineEdit(QWidget *parent)
connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
connect(this, SIGNAL(textChanged(const QString &)), this, SLOT(updateCloseButton(const QString &))); connect(this, SIGNAL(textChanged(const QString &)), this, SLOT(updateCloseButton(const QString &)));
clearButtonSizeHintWidth = clearButton->sizeHint().width(); clearButtonHint = clearButton->sizeHint();
clearButtonSizeHintHeight = clearButton->sizeHint().height(); setStyleSheet(QString("QLineEdit { padding-left: %1px; padding-right: %2px; }").arg(searchButtonHint.width()).arg(clearButtonHint.width()));
setStyleSheet(QString("QLineEdit { padding-left: %1px; padding-right: %2px; }").arg(searchButton->sizeHint().width()).arg(clearButtonSizeHintWidth));
#else #else
setClearButtonEnabled(true); setClearButtonEnabled(true);
setStyleSheet(QString("QLineEdit { padding-left: %1px; }").arg(searchButton->sizeHint().width())); // padding between text and widget borders setStyleSheet(QString("QLineEdit { padding-left: %1px; }").arg(searchButtonHint.width())); // padding between text and widget borders
#endif #endif
QSize msz = sizeHint(); QSize widgetHint = sizeHint();
setMinimumSize(qMax(msz.width(), searchButton->sizeHint().width() + clearButtonSizeHintWidth), int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
std::max({ msz.height(), searchButton->sizeHint().height(), clearButtonSizeHintHeight }) + frameWidth * 2); setMaximumHeight(std::max({ widgetHint.height(), searchButtonHint.height(), clearButtonHint.height() }) + frameWidth * 2);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
} }
void LineEdit::resizeEvent(QResizeEvent *e) void LineEdit::resizeEvent(QResizeEvent *e)

Loading…
Cancel
Save