diff --git a/src/widget/wsearchlineedit.cpp b/src/widget/wsearchlineedit.cpp index 2b53f2c71919..eedfa7664c02 100644 --- a/src/widget/wsearchlineedit.cpp +++ b/src/widget/wsearchlineedit.cpp @@ -393,8 +393,8 @@ void WSearchLineEdit::slotDisableSearch() { return; } setTextBlockSignals(kDisabledText); - updateClearAndDropdownButton(QString()); setEnabled(false); + updateClearAndDropdownButton(QString()); } void WSearchLineEdit::enableSearch(const QString& text) { @@ -576,39 +576,31 @@ void WSearchLineEdit::updateClearAndDropdownButton(const QString& text) { << "updateClearAndDropdownButton" << text; #endif // ENABLE_TRACE_LOG - int paddingPx; - if (text.isEmpty()) { - // Disable while placeholder is shown - m_clearButton->setVisible(false); - // No padding - paddingPx = 0; - } else { - // Enable otherwise - m_clearButton->setVisible(true); - // Ensure the text is not obscured by the clear button - paddingPx = m_innerHeight; - } + // Hide clear button if the text is empty and while placeholder is shown, + // see disableSearch() + m_clearButton->setVisible(!text.isEmpty()); - QString clearPos; - if (layoutDirection() == Qt::RightToLeft) { - clearPos = "left"; - } else { - clearPos = "right"; - } + // Ensure the text is not obscured by the clear button. Otherwise no text, + // no clear button, so the placeholder should use the entire width. + const int paddingPx = text.isEmpty() ? 0 : m_innerHeight; + const QString clearPos(layoutDirection() == Qt::RightToLeft ? "left" : "right"); + + // Hide the nonfunctional drop-down button if the search is disabled. + const int dropDownWidth = isEnabled() ? static_cast(m_innerHeight * 0.7) : 0; - QString styleSheet = QStringLiteral( + const QString styleSheet = QStringLiteral( "WSearchLineEdit { padding-%1: %2px; }" - // With every paintEvent(?) the width of the drop-down button is reset - // to default, so we need to re-adjust it. + // With every paintEvent(?) the width of the drop-down button + // is reset to default, so we need to re-adjust it. "WSearchLineEdit::down-arrow," "WSearchLineEdit::drop-down {" "subcontrol-origin: padding;" "subcontrol-position: %1 center;" "width: %3; height: %4;}") - .arg(clearPos, - QString::number(paddingPx), - QString::number(static_cast(m_innerHeight * 0.7)), - QString::number(m_innerHeight)); + .arg(clearPos, + QString::number(paddingPx), + QString::number(dropDownWidth), + QString::number(m_innerHeight)); setStyleSheet(styleSheet); }