Skip to content

Commit

Permalink
fixup! Searchbox: resize down arrow with font size
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Dec 16, 2021
1 parent 8a32cde commit ece2f6d
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions src/widget/wsearchlineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ void WSearchLineEdit::slotDisableSearch() {
return;
}
setTextBlockSignals(kDisabledText);
updateClearAndDropdownButton(QString());
setEnabled(false);
updateClearAndDropdownButton(QString());
}

void WSearchLineEdit::enableSearch(const QString& text) {
Expand Down Expand Up @@ -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<int>(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<int>(m_innerHeight * 0.7)),
QString::number(m_innerHeight));
.arg(clearPos,
QString::number(paddingPx),
QString::number(dropDownWidth),
QString::number(m_innerHeight));
setStyleSheet(styleSheet);
}

Expand Down

0 comments on commit ece2f6d

Please sign in to comment.