[Development] High-dpi Qt best practices

Olivier Goffart olivier at woboq.com
Tue Oct 9 13:53:34 CEST 2012


On Tuesday 09 October 2012 10:50:26 Sorvig Morten wrote:
> On Oct 9, 2012, at 12:21 PM, Olivier Goffart <olivier at woboq.com>
> 
>  wrote:
> > 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.

I think you expect the resulting pixmap to be smaller than the given size so 
you can draw it in another pixmap using those size constraints.
The size should have been computed in accordance to where it goes. Maybe using 
QWidget::height() and with()   are those in pixel or in point?

 
> 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.

We use QSize and not QPoint or QPair<int,int>  to take advantage of the C++ 
type system.  I have the impression that QSize is used everywhere else in 
pixel. Or do you have an example where it is not?

That is why I think having different type for size in point and size in pixel 
is a good idea.
 
> > 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

Of course, that might be when create a QIcon or pass it arounf.  But there is 
much less use of QIcon::pixmap.

Have a look at the tooltips there for all the uses of QIcon::pixmap in KDE:
http://code.woboq.org/kde/qt4/src/gui/image/qicon.h.html#_ZNK5QIcon6pixmapERK5QSizeNS_4ModeENS_5StateE


> >> This is a behaviour change that breaks existing code (in applications and
> >> in Qt), so it's opt-in via QT_HIDPI_AWARE. 

I don't think having opt in like that is a good idea. It will be a mess when 
you mix different libraries or piece of code together.
That is why I think one need an explicit way to do it.

Can I have a link to the gerrit change?

-- 
Olivier

Woboq - Qt services and support - http://woboq.com





 




More information about the Development mailing list