QLineEdit: Extract Method shouldShowPlaceholderText()
The condition under which the placeholder text should be shown changed recently, so refactor the code to centralize the condition. It turns out that setPlaceholderText() and paintEvent() disagree on the condition already. Change-Id: Id193a9a138042ab0690082dcf634cf7487a5276e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
parent
1c046369e3
commit
6f54244660
@ -350,7 +350,7 @@ void QLineEdit::setPlaceholderText(const QString& placeholderText)
|
||||
Q_D(QLineEdit);
|
||||
if (d->placeholderText != placeholderText) {
|
||||
d->placeholderText = placeholderText;
|
||||
if (d->control->text().isEmpty())
|
||||
if (d->shouldShowPlaceholderText())
|
||||
update();
|
||||
}
|
||||
}
|
||||
@ -1895,7 +1895,7 @@ void QLineEdit::paintEvent(QPaintEvent *)
|
||||
int minLB = qMax(0, -fm.minLeftBearing());
|
||||
int minRB = qMax(0, -fm.minRightBearing());
|
||||
|
||||
if (d->control->text().isEmpty() && d->control->preeditAreaText().isEmpty()) {
|
||||
if (d->shouldShowPlaceholderText() && d->control->preeditAreaText().isEmpty()) {
|
||||
if (!d->placeholderText.isEmpty()) {
|
||||
QColor col = pal.text().color();
|
||||
col.setAlpha(128);
|
||||
|
@ -148,6 +148,10 @@ public:
|
||||
{
|
||||
return !control->isReadOnly();
|
||||
}
|
||||
inline bool shouldShowPlaceholderText() const
|
||||
{
|
||||
return control->text().isEmpty();
|
||||
}
|
||||
|
||||
static inline QLineEditPrivate *get(QLineEdit *lineEdit) {
|
||||
return lineEdit->d_func();
|
||||
|
Loading…
Reference in New Issue
Block a user