[Interest] How to detect a HiDPI display with Qt?

Jérôme Godbout godboutj at amotus.ca
Mon Mar 18 19:15:26 CET 2019


You can also check the device pixel ratio for image “@2” alike:

qreal pixel_ratio = QGuiApplication::primaryScreen()->devicePixelRatio();
unsigned int image_scale_ratio = pixel_ratio / 1u;
QString m_image_scale = image_scale_ratio <= 1u ? "" : QString("@%1x").arg(image_scale_ratio);

This is what I do.

[36E56279]
une compagnie  [cid:image008.jpg at 01D4DD95.0986ECD0]
RAPPROCHEZ LA DISTANCE

Jérôme Godbout
Développeur Logiciel Sénior /
Senior Software Developer

p: +1 (418) 800-1073 ext.:109

amotus.ca<http://www.amotus-solutions.com/>
statum-iot.com<http://statum-iot.com/>
[cid:image009.png at 01D4DD95.0986ECD0]<https://www.facebook.com/LesSolutionsAmotus/> [cid:image010.png at 01D4DD95.0986ECD0] <https://www.linkedin.com/company/amotus-solutions/>  [cid:image011.png at 01D4DD95.0986ECD0] <https://twitter.com/AmotusSolutions>  [cid:image012.jpg at 01D4DD95.0986ECD0] <https://www.youtube.com/channel/UCoYpQgsmj1iJZyDjTQ3x8Ig>





From: Interest <interest-bounces at qt-project.org> On Behalf Of Jérôme Godbout
Sent: March 18, 2019 2:13 PM
To: Vadim Peretokin <vperetokin at gmail.com>; interestqt-project.org <interest at qt-project.org>
Subject: Re: [Interest] How to detect a HiDPI display with Qt?

You can check the dpi of the screen:
QGuiApplication::primaryScreen()->logicalDotsPerInch();

You can then check if the dpi is above certain threshold to do thing differently. Normal desktop full HD screen dpi is around 96.


[36E56279]
une compagnie  [cid:image014.jpg at 01D4DD95.0986ECD0]
RAPPROCHEZ LA DISTANCE

Jérôme Godbout
Développeur Logiciel Sénior /
Senior Software Developer

p: +1 (418) 800-1073 ext.:109

amotus.ca<http://www.amotus-solutions.com/>
statum-iot.com<http://statum-iot.com/>
[cid:image015.png at 01D4DD95.0986ECD0]<https://www.facebook.com/LesSolutionsAmotus/> [cid:image016.png at 01D4DD95.0986ECD0] <https://www.linkedin.com/company/amotus-solutions/>  [cid:image017.png at 01D4DD95.0986ECD0] <https://twitter.com/AmotusSolutions>  [cid:image018.jpg at 01D4DD95.0986ECD0] <https://www.youtube.com/channel/UCoYpQgsmj1iJZyDjTQ3x8Ig>





From: Interest <interest-bounces at qt-project.org<mailto:interest-bounces at qt-project.org>> On Behalf Of Vadim Peretokin
Sent: March 18, 2019 1:00 PM
To: interestqt-project.org <interest at qt-project.org<mailto:interest at qt-project.org>>
Subject: [Interest] How to detect a HiDPI display with Qt?

I'm not clear on how to detect if a display is HiDPI with Qt. I've tried QApplication.desktop()->screen()->devicePixelRatio() but even that returns 1 for a display that is 3840x2160.

Has anyone got hints on how to do this successfully?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190318/60459323/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image007.jpg
Type: image/jpeg
Size: 6751 bytes
Desc: image007.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190318/60459323/attachment-0006.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image008.jpg
Type: image/jpeg
Size: 1016 bytes
Desc: image008.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190318/60459323/attachment-0007.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image009.png
Type: image/png
Size: 483 bytes
Desc: image009.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190318/60459323/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image010.png
Type: image/png
Size: 506 bytes
Desc: image010.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190318/60459323/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image011.png
Type: image/png
Size: 500 bytes
Desc: image011.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190318/60459323/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image012.jpg
Type: image/jpeg
Size: 713 bytes
Desc: image012.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190318/60459323/attachment-0008.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image013.jpg
Type: image/jpeg
Size: 6751 bytes
Desc: image013.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190318/60459323/attachment-0009.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image014.jpg
Type: image/jpeg
Size: 1016 bytes
Desc: image014.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190318/60459323/attachment-0010.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image015.png
Type: image/png
Size: 483 bytes
Desc: image015.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190318/60459323/attachment-0009.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image016.png
Type: image/png
Size: 506 bytes
Desc: image016.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190318/60459323/attachment-0010.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image017.png
Type: image/png
Size: 500 bytes
Desc: image017.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190318/60459323/attachment-0011.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image018.jpg
Type: image/jpeg
Size: 713 bytes
Desc: image018.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190318/60459323/attachment-0011.jpg>


More information about the Interest mailing list