From bf5c7f6d4b7c514bf93727df435e98c5bb12aa41 Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Tue, 20 Jan 2015 01:27:27 +0100 Subject: [PATCH] pass widget window to icon when getting pixmap --- src/widgets/styles/qcommonstyle.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index c688462..8582aa6 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -80,6 +80,14 @@ QT_BEGIN_NAMESPACE +static QWindow *qWidgetWindow(const QWidget *widget) +{ + if (widget && widget->window()) + return widget->window()->windowHandle(); + else + return 0; +} + /*! \class QCommonStyle \brief The QCommonStyle class encapsulates the common Look and Feel of a GUI. @@ -395,7 +403,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q mode = QIcon::Disabled; QIcon::State state = opt->state & State_Sunken ? QIcon::On : QIcon::Off; - QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(size, mode, state); + QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(qWidgetWindow(widget), QSize(size, size), mode, state); proxy()->drawItemPixmap(p, opt->rect, Qt::AlignCenter, pixmap); break; } @@ -1237,7 +1245,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, if (button->state & State_On) state = QIcon::On; - QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state); + QPixmap pixmap = button->icon.pixmap(qWidgetWindow(widget), button->iconSize, mode, state); int pixmapWidth = pixmap.width() / pixmap.devicePixelRatio(); int pixmapHeight = pixmap.height() / pixmap.devicePixelRatio(); @@ -1314,7 +1322,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, QPixmap pix; QRect textRect = btn->rect; if (!btn->icon.isNull()) { - pix = btn->icon.pixmap(btn->iconSize, btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled); + pix = btn->icon.pixmap(qWidgetWindow(widget), btn->iconSize, btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled); proxy()->drawItemPixmap(p, btn->rect, alignment, pix); if (btn->direction == Qt::RightToLeft) textRect.setRight(textRect.right() - btn->iconSize.width() - 4); @@ -1355,7 +1363,8 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, | Qt::TextSingleLine; if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget)) alignment |= Qt::TextHideMnemonic; - QPixmap pix = mbi->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), (mbi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); + int extent = proxy()->pixelMetric(PM_SmallIconSize); + QPixmap pix = mbi->icon.pixmap(qWidgetWindow(widget), QSize(extent, extent), (mbi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); if (!pix.isNull()) proxy()->drawItemPixmap(p,mbi->rect, alignment, pix); else @@ -1519,8 +1528,9 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, if (const QStyleOptionHeader *header = qstyleoption_cast(opt)) { QRect rect = header->rect; if (!header->icon.isNull()) { + int extent = proxy()->pixelMetric(PM_SmallIconSize); QPixmap pixmap - = header->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), (header->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); + = header->icon.pixmap(qWidgetWindow(widget), QSize(extent, extent), (header->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); int pixw = pixmap.width() / pixmap.devicePixelRatio(); QRect aligned = alignedRect(header->direction, QFlag(header->iconAlignment), pixmap.size() / pixmap.devicePixelRatio(), rect); @@ -1579,7 +1589,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, mode = QIcon::Active; else mode = QIcon::Normal; - pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(toolbutton->iconSize), + pm = toolbutton->icon.pixmap(qWidgetWindow(widget), toolbutton->rect.size().boundedTo(toolbutton->iconSize), mode, state); pmSize = pm.size() / pm.devicePixelRatio(); } @@ -1800,7 +1810,8 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, if (const QStyleOptionToolBox *tb = qstyleoption_cast(opt)) { bool enabled = tb->state & State_Enabled; bool selected = tb->state & State_Selected; - QPixmap pm = tb->icon.pixmap(proxy()->pixelMetric(QStyle::PM_SmallIconSize, tb, widget), + int extent = proxy()->pixelMetric(QStyle::PM_SmallIconSize, tb, widget); + QPixmap pm = tb->icon.pixmap(qWidgetWindow(widget), QSize(extent, extent), enabled ? QIcon::Normal : QIcon::Disabled); QRect cr = subElementRect(QStyle::SE_ToolBoxTabContents, tb, widget); @@ -1875,7 +1886,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, tr = proxy()->subElementRect(SE_TabBarTabText, opt, widget); //we compute tr twice because the style may override subElementRect if (!tabV2.icon.isNull()) { - QPixmap tabIcon = tabV2.icon.pixmap(tabV2.iconSize, + QPixmap tabIcon = tabV2.icon.pixmap(qWidgetWindow(widget), tabV2.iconSize, (tabV2.state & State_Enabled) ? QIcon::Normal : QIcon::Disabled, (tabV2.state & State_Selected) ? QIcon::On @@ -2079,7 +2090,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, if (!cb->currentIcon.isNull()) { QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; - QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode); + QPixmap pixmap = cb->currentIcon.pixmap(qWidgetWindow(widget), cb->iconSize, mode); QRect iconRect(editRect); iconRect.setWidth(cb->iconSize.width() + 4); iconRect = alignedRect(cb->direction, @@ -2378,7 +2389,7 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt, if (!btn->icon.isNull()) { iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, - btn->icon.pixmap(btn->iconSize, QIcon::Normal)); + btn->icon.pixmap(qWidgetWindow(widget), btn->iconSize, QIcon::Normal)); if (!textRect.isEmpty()) textRect.translate(iconRect.right() + 4, 0); } @@ -2426,7 +2437,7 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt, } if (!btn->icon.isNull()) { iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, - btn->icon.pixmap(btn->iconSize, QIcon::Normal)); + btn->icon.pixmap(qWidgetWindow(widget), btn->iconSize, QIcon::Normal)); if (!textRect.isEmpty()) textRect.translate(iconRect.right() + 4, 0); } -- 1.9.3 (Apple Git-50)