In a PyQt4 Gui, I require the careful placement of multiple QPainter Pixmaps.
When specifying the coordinates and height and width of the new Pixmaps, I require that all units be in pixels.
(Otherwise, my Gui would be ruined on a screen of a different resolution to my own).
When placing the Pixmap, I use DrawPixmap( QRect , QPixmap ) function.
The Pixmaps needed to be placed are in a list of QRects of Tuples of 4 integers, which specify the coordinates of the top-left corner of the Pixmap (in px) and te bottom-right corner of the Pixmap (in px).
eg:
Blocks = [QtCore.QRect(x1, y1, x2, y2), etc].
Sadly, The last two numbers of the tuple are interpreted as width and height when passed to DrawPixmap( QRect, QPixmap), which are in the units (cm).
My Question…
Is there a method to specify a Pixmaps dimensions entirely in pixels?
(Either by passing a pixel width and height, or the two pixel coordinates of the corners of the dimension box).
I Can’t find a way in the QPainter or QRect class references.
Thanks!
Specs:
Python 2.7
PyQt4
Windows 7 32bit
IDLE
In the
QPainterclass reference, you can find different overloading of thedrawPixmapmethod. Reading the documentation tells thatQPainter::drawPixamp(QRect, QPixmap)do exactly what you want. It might be a specific issue with pyqt where the format of theQRectis recognized more as aQRectF. You can also use the overloaded function that gets the top left coordinates and the width and height of your area like:QPainter::drawPixamp(x, y, width, height, QPixmap)