Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.4.0
-
None
-
At least Mac OS X 10.10.2, probably earlier versions. Since this is code in QCommonStyle.cpp, it probably affects all platforms, but perhaps only Macintosh has the ability to have more than one resolution.
-
74a2e29705c283a6f52cf007a14a552cf529d051
Description
On Macintosh OS X 10.10.2 (or as early as there was Retina support).
Make a QToolButton (or probably any kind of button as long as it has an icon for the label). My system has both a Retina display and a standard resolution monitor (it's a 5K iMac with external monitor). QCommonStyle::drawControl() when asked by a QToolButton to draw its label (QStyle::CE_ToolButtonLabel), uses QIcon::pixmap() to get the icon's QPixmap. The icon has both a regular icon and @2x icon, but since the call isn't the one that passes in a QWindow, it calls QApplication::devicePixelRatio() to determine the resolution. That returns the resolution of the highest-resolution monitor on the system NOT the resolution of the monitor where the button resides.
QPaintDevice::devicePixelRatio() has the correct resolution, but QIcon has no call to get a pixmap using the QPaintDevice. So one solution would be for QIcon::pixmap( ) to have an overload that takes a QPainter or QPaintDevice as input.
In the absence of the appropriate QIcon API, you can still get the right QPixmap using the overload of QIcon::pixmap() that takes a QWindow * as input. In my own code, I use this to get the QWindow *:
QWindow * QWindowHostForQWidget(const QWidget *widget) { QWindow * toplevel = NULL; QWidget * theParent = widget->parentWidget(); do { toplevel = theParent->windowHandle(); theParent = theParent->parentWidget(); } while(toplevel == NULL && theParent != NULL); return toplevel; }
However it is done, though, QStyle::CE_ToolButtonLabel should draw icons that match the device's resolution when one is available.