Skip to content

Commit

Permalink
Style sheets: detect and apply font set on QHeaderView section
Browse files Browse the repository at this point in the history
Detect and apply style sheets font set when calculating
QHeaderView section content size and drawing it.

Change-Id: I542cd0d31bbe62f127c509f297eef0a576fec054
Task-number: QTBUG-55597
Reviewed-by: Olivier Goffart (Woboq GmbH) <[email protected]>
  • Loading branch information
pengwu authored and xknight committed Sep 4, 2016
1 parent 24bd7fd commit b941111
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/widgets/styles/qstylesheetstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3753,6 +3753,13 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
ParentStyle::drawControl(ce, opt, p, w);
return;
}
if (subRule.hasFont) {
const QFont oldFont = p->font();
p->setFont(subRule.font.resolve(p->font()));
baseStyle()->drawControl(ce, opt, p, w);
p->setFont(oldFont);
return;
}
}
break;
case CE_HeaderSection:
Expand Down Expand Up @@ -4866,13 +4873,14 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op
case CT_HeaderSection: {
if (const QStyleOptionHeader *hdr = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
QRenderRule subRule = renderRule(w, opt, PseudoElement_HeaderViewSection);
if (subRule.hasGeometry() || subRule.hasBox() || !subRule.hasNativeBorder()) {
if (subRule.hasGeometry() || subRule.hasBox() || !subRule.hasNativeBorder() || subRule.hasFont) {
sz = subRule.adjustSize(csz);
if (!subRule.hasGeometry()) {
QSize nativeContentsSize;
bool nullIcon = hdr->icon.isNull();
int iconSize = nullIcon ? 0 : pixelMetric(QStyle::PM_SmallIconSize, hdr, w);
QSize txt = hdr->fontMetrics.size(0, hdr->text);
const QSize txt = subRule.hasFont ? QFontMetrics(subRule.font).size(0, hdr->text)
: hdr->fontMetrics.size(0, hdr->text);
nativeContentsSize.setHeight(qMax(iconSize, txt.height()));
nativeContentsSize.setWidth(iconSize + txt.width());
sz = sz.expandedTo(nativeContentsSize);
Expand Down

0 comments on commit b941111

Please sign in to comment.