TextItem performance
Avoid expensive work if textitem is not visible, or when setPlainText / setHtml would have no effect.
This commit is contained in:
parent
6f69b11c26
commit
268d25c125
@ -67,26 +67,33 @@ class TextItem(GraphicsObject):
|
|||||||
"""
|
"""
|
||||||
if color is not None:
|
if color is not None:
|
||||||
self.setColor(color)
|
self.setColor(color)
|
||||||
self.textItem.setPlainText(text)
|
self.setPlainText(text)
|
||||||
self.updateTextPos()
|
|
||||||
|
def setPlainText(self, text):
|
||||||
def setPlainText(self, *args):
|
|
||||||
"""
|
"""
|
||||||
Set the plain text to be rendered by this item.
|
Set the plain text to be rendered by this item.
|
||||||
|
|
||||||
See QtGui.QGraphicsTextItem.setPlainText().
|
See QtGui.QGraphicsTextItem.setPlainText().
|
||||||
"""
|
"""
|
||||||
self.textItem.setPlainText(*args)
|
if text != self.toPlainText():
|
||||||
self.updateTextPos()
|
self.textItem.setPlainText(text)
|
||||||
|
self.updateTextPos()
|
||||||
|
|
||||||
|
def toPlainText(self):
|
||||||
|
return self.textItem.toPlainText()
|
||||||
|
|
||||||
def setHtml(self, *args):
|
def setHtml(self, html):
|
||||||
"""
|
"""
|
||||||
Set the HTML code to be rendered by this item.
|
Set the HTML code to be rendered by this item.
|
||||||
|
|
||||||
See QtGui.QGraphicsTextItem.setHtml().
|
See QtGui.QGraphicsTextItem.setHtml().
|
||||||
"""
|
"""
|
||||||
self.textItem.setHtml(*args)
|
if self.toHtml() != html:
|
||||||
self.updateTextPos()
|
self.textItem.setHtml(html)
|
||||||
|
self.updateTextPos()
|
||||||
|
|
||||||
|
def toHtml(self):
|
||||||
|
return self.textItem.toHtml()
|
||||||
|
|
||||||
def setTextWidth(self, *args):
|
def setTextWidth(self, *args):
|
||||||
"""
|
"""
|
||||||
@ -176,7 +183,15 @@ class TextItem(GraphicsObject):
|
|||||||
p.setRenderHint(p.Antialiasing, True)
|
p.setRenderHint(p.Antialiasing, True)
|
||||||
p.drawPolygon(self.textItem.mapToParent(self.textItem.boundingRect()))
|
p.drawPolygon(self.textItem.mapToParent(self.textItem.boundingRect()))
|
||||||
|
|
||||||
|
def setVisible(self, v):
|
||||||
|
GraphicsObject.setVisible(self, v)
|
||||||
|
if v:
|
||||||
|
self.updateTransform()
|
||||||
|
|
||||||
def updateTransform(self, force=False):
|
def updateTransform(self, force=False):
|
||||||
|
if not self.isVisible():
|
||||||
|
return
|
||||||
|
|
||||||
# update transform such that this item has the correct orientation
|
# update transform such that this item has the correct orientation
|
||||||
# and scaling relative to the scene, but inherits its position from its
|
# and scaling relative to the scene, but inherits its position from its
|
||||||
# parent.
|
# parent.
|
||||||
|
Loading…
Reference in New Issue
Block a user