QCommandLinkButton: Let the style set the text colors
Make the hack less hacky by letting the style polish the widget (it does already for the font) to set a dynamic property that the button can test. Use the available palette entires ButtonText and BrightText to set the dark blue and bright blue colors, rather than hardcoding them in the widget code. Change-Id: Idfb3b7d18e456a9d14af4962cf723e12ff1c3370 Reviewed-by: Doris Verria <doris.verria@qt.io> (cherry picked from commit 86d973ed077b3e8e89571b2c3327f15d3ad89eed) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
bc3e6af3ce
commit
5f1c3fc935
@ -2263,9 +2263,14 @@ void QWindowsVistaStyle::polish(QWidget *widget)
|
||||
widget->setAttribute(Qt::WA_Hover);
|
||||
#if QT_CONFIG(commandlinkbutton)
|
||||
else if (qobject_cast<QCommandLinkButton*>(widget)) {
|
||||
widget->setProperty("_qt_usingVistaStyle", true);
|
||||
QFont buttonFont = widget->font();
|
||||
buttonFont.setFamilies(QStringList{QLatin1String("Segoe UI")});
|
||||
widget->setFont(buttonFont);
|
||||
QPalette pal = widget->palette();
|
||||
pal.setColor(QPalette::ButtonText, QColor(21, 28, 85));
|
||||
pal.setColor(QPalette::BrightText, QColor(7, 64, 229));
|
||||
widget->setPalette(pal);
|
||||
}
|
||||
#endif // QT_CONFIG(commandlinkbutton)
|
||||
else if (widget->inherits("QTipLabel")){
|
||||
|
@ -171,7 +171,7 @@ bool QCommandLinkButtonPrivate::usingVistaStyle() const
|
||||
Q_Q(const QCommandLinkButton);
|
||||
//### This is a hack to detect if we are indeed running Vista style themed and not in classic
|
||||
// When we add api to query for this, we should change this implementation to use it.
|
||||
return q->style()->inherits("QWindowsVistaStyle")
|
||||
return q->property("_qt_usingVistaStyle").toBool()
|
||||
&& q->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal, nullptr) == 0;
|
||||
}
|
||||
|
||||
@ -339,9 +339,9 @@ void QCommandLinkButton::paintEvent(QPaintEvent *)
|
||||
//Draw title
|
||||
QColor textColor = palette().buttonText().color();
|
||||
if (isEnabled() && d->usingVistaStyle()) {
|
||||
textColor = QColor(21, 28, 85);
|
||||
textColor = option.palette.buttonText().color();
|
||||
if (underMouse() && !isDown())
|
||||
textColor = QColor(7, 64, 229);
|
||||
textColor = option.palette.brightText().color();
|
||||
//A simple text color transition
|
||||
d->currentColor = d->mergedColors(textColor, d->currentColor, 60);
|
||||
option.palette.setColor(QPalette::ButtonText, d->currentColor);
|
||||
|
Loading…
x
Reference in New Issue
Block a user