[Development] High-dpi Qt best practices

Sorvig Morten Morten.Sorvig at digia.com
Tue Oct 9 12:50:26 CEST 2012

On Oct 9, 2012, at 12:21 PM, Olivier Goffart <olivier at woboq.com>

> On Tuesday 09 October 2012 09:46:37 Sorvig Morten wrote:
>> On Oct 9, 2012, at 11:32 AM, Olivier Goffart <olivier at woboq.com>
>> wrote:
>>> But QSize is already the size in pixel.
>>> Or do you mean that QIcon::pixmap could return a pixmap that is larger
>>> than
>>> the given QSize, scaled with some magic heuristics.  That is not really
>>> intuitive. (and violate the current documentation)
>> I'm re-defining it to be the size in points. I think this intuitive, you are
>> asking QIcon::pixmap() for pixmap suitable for covering this many units on
>> screen - not for a pixmap of a specific size.
> What is an "unit on screen"?  Is it not a pixel?

In this context it is a point - the unit that does not change when you enable high-dpi mode. 

Apple has quite comprehensive documentation about this topic: http://tinyurl.com/8me4yzz is recommended background material for those who are interested.

> When you have do QImage(QSize),  the image has hight*width pixel, right?
> Same for QPixmap?  or has a pixmap actually more pixal than its size? (as 
> returned by QPixmap::size/width/height)

Pixmaps and images _always_ have exactly QPixmap::size() pixels.

> Maybe we can introduce QSizePt
> Code would look like
> QPixmap p = QIcon::pixmap(QSizePt(20,20).toSize(window));
> (but then again, i'd say it is bad practice to even hardcode pt size)

I don't know.. to me QSize is just a pair of ints, it does not have a unit.

> I think there should not be that may use of QIcon::pixmap anyway.  It is 
> mainly going to be used handled QToolBar and similar.

Then it has to work for QToolBar. But I think it's used a fair bit in Qt:
widgets msorvig$ git grep QIcon | wc
     668    3666   59429


More information about the Development mailing list