QRect 宽度和高度(以像素为单位)?
在 PyQt4 Gui 中,我需要仔细放置多个 QPainter Pixmap。
当指定新像素图的坐标以及高度和宽度时,我要求所有单位都以像素为单位。
(否则,我的 Gui 将在与我的分辨率不同的屏幕上被毁掉)。
放置 Pixmap 时,我使用 DrawPixmap( QRect , QPixmap ) 函数。
需要放置的像素图位于 4 个整数元组的 QRect 列表中,它指定像素图的左上角(以 px 为单位)和右下角(以 px 为单位)的坐标。< br> 例如:
块 = [QtCore.QRect(x1, y1, x2, y2), 等等]。
遗憾的是,当传递给 DrawPixmap(QRect, QPixmap) 时,元组的最后两个数字被解释为宽度和高度,其单位为 (cm)。
我的问题...
有没有一种方法可以完全以像素为单位指定 Pixmaps 尺寸?
(通过传递像素宽度和高度,或者尺寸框角的两个像素坐标)。
我在 QPainter 或 QRect 类引用中找不到方法。
谢谢!
规格:
Python 2.7
PyQt4
Windows 7 32位
闲置的
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
QPainter
类参考中,您可以找到drawPixmap
方法的不同重载。阅读 文档 得知QPainter::drawPixamp(QRect, QPixmap)
完全按照您的意愿行事。这可能是 pyqt 的一个特定问题,其中QRect
的格式更多地被识别为QRectF
。您还可以使用重载函数来获取区域的左上角坐标以及宽度和高度,例如:QPainter::drawPixamp(x, y, width, height, QPixmap)
In the
QPainter
class reference, you can find different overloading of thedrawPixmap
method. 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 theQRect
is 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)