diff options
Diffstat (limited to 'src/widgets/styles/qstylesheetstyle.cpp')
-rw-r--r-- | src/widgets/styles/qstylesheetstyle.cpp | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 34f23d1b19..11d6f4649f 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -121,6 +121,9 @@ #if QT_CONFIG(toolbar) #include <QtWidgets/qtoolbar.h> #endif +#if QT_CONFIG(pushbutton) +#include <QtWidgets/qpushbutton.h> +#endif #include <QtGui/qpainterpath.h> #include <QtGui/qscreen.h> @@ -1462,7 +1465,11 @@ void QRenderRule::configurePalette(QPalette *p, QPalette::ColorGroup cg, const Q p->setBrush(cg, w->foregroundRole(), pal->foreground); p->setBrush(cg, QPalette::WindowText, pal->foreground); p->setBrush(cg, QPalette::Text, pal->foreground); - p->setBrush(cg, QPalette::PlaceholderText, pal->foreground); + QColor phColor(pal->foreground.color()); + phColor.setAlpha((phColor.alpha() + 1) / 2); + QBrush placeholder = pal->foreground; + placeholder.setColor(phColor); + p->setBrush(cg, QPalette::PlaceholderText, placeholder); } if (pal->selectionBackground.style() != Qt::NoBrush) p->setBrush(cg, QPalette::Highlight, pal->selectionBackground); @@ -2438,11 +2445,12 @@ static QWidget *embeddedWidget(QWidget *w) } /** \internal - in case w is an embedded widget, return the container widget - (i.e, the widget for which the rules actualy apply) - (exemple, if w is a lineedit embedded in a combobox, return the combobox) + Returns the widget whose style rules apply to \a w. + + When \a w is an embedded widget, this is the container widget. + For example, if w is a line edit embedded in a combobox, this returns the combobox. + When \a w is not embedded, this function return \a w itself. - if w is not embedded, return w itself */ static QWidget *containerWidget(const QWidget *w) { @@ -2646,6 +2654,9 @@ void QStyleSheetStyle::setProperties(QWidget *w) default: v = decl.d->values.at(0).variant; break; } + if (propertyL1 == "styleSheet" && value == v) + continue; + w->setProperty(propertyL1, v); } } @@ -2928,6 +2939,12 @@ void QStyleSheetStyle::polish(QWidget *w) if (!rule.hasBackground() || rule.background()->isTransparent() || rule.hasBox() || (!rule.hasNativeBorder() && !rule.border()->isOpaque())) w->setAttribute(Qt::WA_OpaquePaintEvent, false); + if (rule.hasBox() || !rule.hasNativeBorder() +#if QT_CONFIG(pushbutton) + || (qobject_cast<QPushButton *>(w)) +#endif + ) + w->setAttribute(Qt::WA_MacShowFocusRect, false); } } @@ -4440,14 +4457,17 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op case PE_PanelLineEdit: if (const QStyleOptionFrame *frm = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { -#if QT_CONFIG(spinbox) - if (w && qobject_cast<const QAbstractSpinBox *>(w->parentWidget())) { - QRenderRule spinboxRule = renderRule(w->parentWidget(), opt); - if (!spinboxRule.hasNativeBorder() || !spinboxRule.baseStyleCanDraw()) - return; - rule = spinboxRule; + // Fall back to container widget's render rule + if (w) { + QWidget *container = containerWidget(w); + if (container && container != w) { + QRenderRule containerRule = renderRule(container, opt); + if (!containerRule.hasNativeBorder() || !containerRule.baseStyleCanDraw()) + return; + rule = containerRule; + } } -#endif + if (rule.hasNativeBorder()) { QStyleOptionFrame frmOpt(*frm); rule.configurePalette(&frmOpt.palette, QPalette::Text, QPalette::Base); @@ -5162,18 +5182,19 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op QSize sz(csz); if (mi->text.contains(QLatin1Char('\t'))) sz.rwidth() += 12; //as in QCommonStyle - bool checkable = mi->checkType != QStyleOptionMenuItem::NotCheckable; if (!mi->icon.isNull()) { const int pmSmall = pixelMetric(PM_SmallIconSize); const QSize pmSize = mi->icon.actualSize(QSize(pmSmall, pmSmall)); - sz.rwidth() += pmSize.width() + 4; - } else if (checkable) { + sz.rwidth() += std::max(mi->maxIconWidth, pmSize.width()) + 4; + } else if (mi->menuHasCheckableItems) { QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); QRect checkmarkRect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); sz.rwidth() += std::max(mi->maxIconWidth, checkmarkRect.width()) + 4; + } else { + sz.rwidth() += mi->maxIconWidth; } if (subRule.hasFont) { - QFontMetrics fm(subRule.font); + QFontMetrics fm(subRule.font.resolve(mi->font)); const QRect r = fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, mi->text); sz = sz.expandedTo(r.size()); } |