diff --git a/src/widget/wsearchlineedit.cpp b/src/widget/wsearchlineedit.cpp index acf39fccf20e..b521453204e9 100644 --- a/src/widget/wsearchlineedit.cpp +++ b/src/widget/wsearchlineedit.cpp @@ -85,13 +85,7 @@ WSearchLineEdit::WSearchLineEdit(QWidget* pParent) m_clearButton->setCursor(Qt::ArrowCursor); m_clearButton->setObjectName(QStringLiteral("SearchClearButton")); // Query style for arrow width and frame border - QStyleOptionComboBox styleArrow; - styleArrow.initFrom(this); - QRect rectArrow(style()->subControlRect( - QStyle::CC_ComboBox, &styleArrow, QStyle::SC_ComboBoxArrow, this)); - - m_dropButtonWidth = rectArrow.width() + 1; - m_frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this); + updateStyleMetrics(); m_clearButton->hide(); connect(m_clearButton, @@ -221,8 +215,19 @@ void WSearchLineEdit::setup(const QDomNode& node, const SkinContext& context) { tr("Esc") + " " + tr("Exit search", "Exit search bar and leave focus")); } +void WSearchLineEdit::updateStyleMetrics() { + QStyleOptionComboBox styleArrow; + styleArrow.initFrom(this); + QRect rectArrow(style()->subControlRect( + QStyle::CC_ComboBox, &styleArrow, QStyle::SC_ComboBoxArrow, this)); + + m_dropButtonWidth = rectArrow.width() + 1; + m_frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this); +} + void WSearchLineEdit::resizeEvent(QResizeEvent* e) { QComboBox::resizeEvent(e); + updateStyleMetrics(); m_innerHeight = this->height() - 2 * m_frameWidth; // Test if this is a vertical resize due to changed library font. // Assuming current button height is innerHeight from last resize, @@ -341,14 +346,14 @@ void WSearchLineEdit::slotSaveSearch() { m_saveTimer.stop(); if (currentText().length()) { int cIndex = findData(currentText(), Qt::DisplayRole); - if (cIndex == -1) { - insertItem(0, currentText()); - setCurrentIndex(0); - while (count() > kMaxSearchEntries) { - removeItem(kMaxSearchEntries); - } - } else { - setCurrentIndex(cIndex); + // we remove the existing item and add a new one at the top + if (cIndex != -1) { + removeItem(cIndex); + } + insertItem(0, currentText()); + setCurrentIndex(0); + while (count() > kMaxSearchEntries) { + removeItem(kMaxSearchEntries); } } } @@ -466,5 +471,6 @@ void WSearchLineEdit::slotSetShortcutFocus() { // Use the same font as the library table and the sidebar void WSearchLineEdit::slotSetFont(const QFont& font) { + updateStyleMetrics(); setFont(font); } diff --git a/src/widget/wsearchlineedit.h b/src/widget/wsearchlineedit.h index c4d929c50c4b..eb1fa9688eee 100644 --- a/src/widget/wsearchlineedit.h +++ b/src/widget/wsearchlineedit.h @@ -67,6 +67,7 @@ class WSearchLineEdit : public QComboBox, public WBaseWidget { void enableSearch(const QString& text); void updateEditBox(const QString& text); void updateClearButton(const QString& text); + void updateStyleMetrics(); QString getSearchText() const;