PDA

View Full Version : Windows 7 Theme Broken ornament: Menu item icon QStyle::PM_SmallIconSize override



philw
11th October 2013, 03:53
LONG TITLE: Broken selected-item ornament with Windows 7 Theme: Menu item icon sized using QStyle::PM_SmallIconSize override.

The ornament which the Windows 7 Theme puts on a selected menu item icon -- made wider using a QStyleProxy overriding the QStyle::PM_SmallIconSize property (see below) -- isn't drawn correctly. [Qt 4.8.5 on Windows 7]. SEE the light blue rounded square ...

9684

http://cadswes2.colorado.edu/~philw/2013/IconMenuOrnProbWin7/images/detail1.png

Note that the Bullet (dot) is part of the icon. This was done because checkable menu items (QActions) having an icon don't show a check indicator -- and we really want the check indicator. [ See thread: "Can Checkable QActions (menu items) with Icons also show check indicators?" ... http://www.qtcentre.org/threads/56473-Checkable-QActions-%28menu-items%29-with-Icons-don-t-show-check-indicators ... ALSO: http://qt-project.org/forums/viewthread/33325/ ].

This problem doesn't exist with the Windows Classic Theme (right side):

9685

http://cadswes2.colorado.edu/~philw/2013/IconMenuOrnProbWin7/images/detail2.png

Here is the QStyle::PM_SmallIconSize override code:


// QProxyStyle sublass to be installed on a QMenu needing to support
// wider-than-usual icons. It overrides the QStyle::PM_SmallIconSize
// property with the width of the QSize provided by the client.

class QMenuIconSizeProxyStyle : public QProxyStyle
{
private:
QSize _iconSize; // note: only the width is currently used.

public:
QMenuIconSizeProxyStyle() : QProxyStyle() {}

void setIconSize (const QSize& iconSize) { _iconSize = iconSize; }

int pixelMetric (QStyle::PixelMetric metric,
const QStyleOption* option=NULL,
const QWidget* widget=NULL) const override
{
if (metric == QStyle::PM_SmallIconSize)
return (_iconSize.width());

// Return base class result
return QProxyStyle::pixelMetric (metric, option, widget);
}
};

... ... ...

// Instantiate a QProxyStyle for a modified QStyle::PM_SmallIconSize
// and install that on the QMenu.

QMenuIconSizeProxyStyle* proxyStyle = new QMenuIconSizeProxyStyle;
proxyStyle->setIconSize (maxIconSize); // QSize
myMenu->setStyle (proxyStyle);

Is there some other QStyle Pixel Metric I can also override which would cause the selected-item Windows 7 ornament to draw correctly (around the full revised-width of the menu icon / check indicator area)? Or is there any other way to fix this?

Reference: http://qt-project.org/doc/qt-4.8/qstyle.html#PixelMetric-enum
[Thank you in advance].