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 ...
detail1.png
http://cadswes2.colorado.edu/~philw/...es/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/5647...eck-indicators ... ALSO: http://qt-project.org/forums/viewthread/33325/ ].
This problem doesn't exist with the Windows Classic Theme (right side):
detail2.png
http://cadswes2.colorado.edu/~philw/...es/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 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);
// 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);
To copy to clipboard, switch view to plain text mode
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/qst...xelMetric-enum
[Thank you in advance].
Bookmarks