QPixmap pixmap(":/images/image.png"); int dpiRatio = pixmap.devicePixelRatio();
QPixmap pixmap(100, 100); QPainter painter(&pixmap); painter.fillRect(QRect(0, 0, 100, 100), Qt::red); int dpiRatio = pixmap.devicePixelRatio();In this example, we create a QPixmap object with a size of 100x100 pixels, and then we create a QPainter object to draw a red rectangle on the pixmap. We then get the devicePixelRatio of the pixmap. The QPixmap class is part of the Qt GUI module.