View Full Version : Pick size of QPixmap / icon based on DPI / user prefs

12th January 2013, 05:33
I want to make a color picker available via a QPushButton. The button should have a color swatch (a QIcon) indication the object's current color. I need this to work adequately on both low and high dpi devices. How can I create an icon of the appropriate size?

Added after 29 minutes:

Here's one possible solution... correct me if there is a better way.

QSomeWidget* widget ...
QFont font = QApplication::font( widget );
QFontMetrics metrics( font );

int size = metrics.height() * 0.75f;
QIcon( size, size );


12th January 2013, 07:54

its not a better way but a shorter one:
const int size = widget->fontMetrics().height() * 0.75f;