Broken selected-item ornament with Windows 7 Theme: Menu item icon sized using QStyle::PM_SmallIconSize override.
-
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 ...
!http://cadswes2.colorado.edu/~philw/2013/IconMenuOrnProbWin7/images/detail1.png(Light Blue Rounded Rectangle is Wrong Size)!
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://qt-project.org/forums/viewthread/33325/ ].
This problem doesn't exist with the Windows Classic Theme (right side):
!http://cadswes2.colorado.edu/~philw/2013/IconMenuOrnProbWin7/images/detail2.png(Windows Classic Theme is OK)!
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].