Qt5
我对( PySide2
) 和Qt4
( )之间的行为差异感到困惑PySide
。我得到的印象是Qt5
有错误,但也许我做错了什么?
简而言之:当QPainterPath
对 a 应用计算时QGraphicsPathItem
(使用setPath
),得到的大小QGraphicsPathItem
比自身的大小大QPainterPath
1.5 个像素。这对我来说毫无意义,而 Qt4 的大小完全相同。
我提供了一段简单的代码来重现 PySide 和 PySide2。
使用 PySide:
#!/usr/bin/env python2
from PySide.QtCore import *
from PySide.QtGui import *
class Foo (QGraphicsPathItem):
def __init__(self, parent):
super(Foo, self).__init__()
path = QPainterPath()
path.addRect(0,0,10,10)
print(str(path.boundingRect()))
self.setPath(path)
print(str(self.boundingRect()))
x=Foo(None)
结果是:
$ python2 ./with_py2.py
PySide.QtCore.QRectF(0.000000, 0.000000, 10.000000, 10.000000)
PySide.QtCore.QRectF(0.000000, 0.000000, 10.000000, 10.000000)
大小相同,符合预期。都好。
与 Qt5 完全相同的代码:
#!/usr/bin/env python3
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
class Foo (QGraphicsPathItem):
def __init__(self, parent):
super(Foo, self).__init__()
path = QPainterPath()
path.addRect(0,0,10,10)
print(str(path.boundingRect()))
self.setPath(path)
print(str(self.boundingRect()))
x=Foo(None)
结果是:
$ python3 bug.py
PySide2.QtCore.QRectF(0.000000, 0.000000, 10.000000, 10.000000)
PySide2.QtCore.QRectF(-0.500000, -0.500000, 11.000000, 11.000000)
有没有人看到任何明显的解释?
谢谢