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

Jérôme Godbout godboutj at amotus.ca
Mon Mar 18 20:25:01 CET 2019


I do Qml, so 

// C++, expose the m_image_scale as a meta property

class MyApp : public QObject
{
	Q_OBJECT
	Q_PROPERTY(QString imageScale read imageScale CONSTANT)
public:
	// MyApp init should extract the string scale as previously stated, this function only returns the QString value.
	QString imageScale() const;
};

// Qml

Image
{
  // Here you can make yourself a method, a sub folder if you want or whatever suites your needs.
  source: "qrc:///image/myImageName" + MyApp.imageScale + ".png"  
}

There's probably a better way to do it, but this I can track what is going on without fiddling too much into obscure under the hood undocumented behavior and the resource are inline with other iOS made images without too much renaming. 

-----Original Message-----
From: Interest <interest-bounces at qt-project.org> On Behalf Of william.crocker at analog.com
Sent: March 18, 2019 2:47 PM
To: interest at qt-project.org
Subject: Re: [Interest] How to detect a HiDPI display with Qt?


>
> 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);
>

Please keep going...

How do you use m_image_scale ?

Bill

_______________________________________________
Interest mailing list
Interest at qt-project.org
https://lists.qt-project.org/listinfo/interest


More information about the Interest mailing list