PDA

View Full Version : Any way to properly handle Windows DPI setting?



vaddimka
12th May 2010, 18:08
I'm using Qt 4.6.2 open source, my application uses QDialog with font sizes in "pt". I noticed that if I choose 125% scaling factor in Windows, font size increases properly, but dialog window size in pixels remains the same.
Is there any way to scale widgets according to Windows settings? It would be great if there's been a way to set widget sizes in "pt" instead of pixels.
Any help is greatly appreciated.

squidge
12th May 2010, 18:39
Are you using layouts?

vaddimka
12th May 2010, 18:57
Are you using layouts?

No, actually I don't. Even if I was, it would mess up some custom formatting. I'd prefer to scale dialog with constrain proportions, AFAIK layouts can't do that.

Zlatomir
12th May 2010, 19:24
If you "hard-code" the dimensions of widgets you get that kind of "errors", so use layouts, it's even easier to write and it's more flexible about any changes like: font size or text length.

What custom formatting? Just try layouts, i'm sure that they will auto-fit your widgets in dialog, just give layouts a chance.
My advice is: start a small project and try to replicate that formatting with widgets in layouts and see how layouts align stuff in your application.

vaddimka
12th May 2010, 19:37
I'm just afraid I won't be able to replicate this design using layouts.

http://img41.imageshack.us/img41/3472/42532607.th.png (http://img41.imageshack.us/i/42532607.png/)

SixDegrees
12th May 2010, 19:43
You could probably toss that layout together in Designer in under an hour. If you're new to Designer. I don't see anything remarkable about it that would require custom layout coding.

ChrisW67
13th May 2010, 00:17
What does that screen look like at "125%" or (worse) "150%"? Please upload the image by attaching it here, not to a third party image host where the image can (will) disappear without warning.

wysota
13th May 2010, 01:43
The left part is QFormLayout, the right part is QVBoxLayout with QGridLayout instances holding particular groups and everything can be placed either in a horizontal splitter or in a QHBoxLayout. It's about 10 minutes of work for a skilled engineer to replicate this layout in Designer.

vaddimka
13th May 2010, 04:48
Thank you for the replies. It took me a while to wrap my head around layouts. I finally managed to get it working, but in some cases the problem still remains. Now I have flexible design and if the window has sufficient size everything is perfect (ok, almost everything).

But still, sometimes minimum size of QCheckBox is calculated incorrectly. Which means it is possible to get something like that when playing with window size:
http://www.deviant.ru/trash/ivmshot2.png
(150% increase or 144 DPI)

I tried to fool around with QSizePolicy (http://doc.trolltech.com/4.6/qsizepolicy.html#Policy-enum ) and ended up with nothing, it's either bug or I'm doing something terribly wrong. Tried "Preferred" and "MinimumExpanding" all the way down through the hierarchy, still no luck.

ChrisW67
13th May 2010, 07:43
What do you want to do with the highlighted radio button label? Wrap the text, grow the enclosing panel, something else?

wysota
13th May 2010, 10:15
Is this what you wanted?

4625

vaddimka
13th May 2010, 12:10
Is this what you wanted?

Man, you're a pro! This masterpiece looks perfect even in bloody 200 DPI. Your design is so simple and efficient. It seems I've been overcomplicating things from the very beginning. Thank you very mush for the example you provided, I finally realized how the things should be done.

vaddimka
14th May 2010, 19:59
Curious observation: if I only change checkbox text from 'Applications started via Secure Launch' to simple 'A', it breaks the whole thing:

This is how the example looks in 200 DPI originally:
4634

This is how it looks after minor modification:
4635

I'm still thinking it must be some kind of bug in Qt.

vaddimka
14th May 2010, 20:10
More on topic!
The bug disappears if I place labels before checkboxes. Labels can have any name (even be empty). I named them as "." for clearness:
4636

Maybe this workaround will come in handy for someone.

wysota
15th May 2010, 03:08
The form layout seems to be a bit broken in this matter. I think it is worth submitting a bug report.

ChrisW67
16th May 2010, 11:03
I had noticed similar behaviour in one or two of my forms where radio button labels in the right form column were truncated. I hadn't tried placing an empty label in the left column. Thanks
vaddimka and Wysota.

I just lodged it as http://bugreports.qt.nokia.com/browse/QTBUG-10726