【发布时间】:2016-09-07 17:31:21
【问题描述】:
[用更小的例子更新]
我们刚刚升级到 PyQt 5.7,我们的应用程序中还有最后一个问题需要修复。这是我从我们的应用程序代码创建的独立示例。运行它,看看椭圆是如何绘制到视图边界之外的。这在 5.5.1 中没有发生。平台是 Windows 7 64 位(在 VM 中运行)。它看起来像这样:
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QGraphicsView, QGraphicsScene, QHBoxLayout, QWidget, QLabel
from PyQt5.QtWidgets import QGraphicsProxyWidget, QGraphicsObject, QGraphicsEllipseItem
from PyQt5.QtGui import QBrush
class MyGraphicsItem(QGraphicsObject):
def __init__(self):
QGraphicsObject.__init__(self)
# next line could be any type of graphics item:
rect_item = QGraphicsEllipseItem(0, 0, 100, 100, self)
# effect easier to see if paint black:
rect_item.setBrush(QBrush(Qt.SolidPattern))
label_item = QGraphicsProxyWidget(self)
# *** Next line must be there for effect to be visible, but could be any other type of widget
label_item.setWidget(QLabel('a'*30))
def paint(self, painter, option, widget=None):
return
def boundingRect(self):
return self.childrenBoundingRect()
def show_problem():
app = QApplication([])
widget = QWidget()
layout = QHBoxLayout()
widget.setLayout(layout)
view = QGraphicsView()
scene = QGraphicsScene()
view.setScene(scene)
scene.addItem(MyGraphicsItem()) # *** effect only there if more than 1 item
scene.addItem(MyGraphicsItem())
layout.addWidget(view)
widget.setGeometry(100, 100, 50, 50)
widget.show()
app.exec()
show_problem()
【问题讨论】: