Merge pull request #291 from lesauxvi/textitem
slight changes in TextItem
This commit is contained in:
commit
0ac914fae7
@ -11,11 +11,16 @@ pyqtgraph-0.9.11 [unreleased]
|
||||
- Remove all modifications to builtins
|
||||
- Fix SpinBox decimals
|
||||
|
||||
API / behavior changes:
|
||||
- Change the defaut color kwarg to None in TextItem.setText() to avoid changing
|
||||
the color everytime the text is changed.
|
||||
|
||||
New Features:
|
||||
- Preliminary PyQt5 support
|
||||
- DockArea:
|
||||
- Dock titles can be changed after creation
|
||||
- Added Dock.sigClosed
|
||||
- Added TextItem.setColor()
|
||||
|
||||
Maintenance:
|
||||
- Add examples to unit tests
|
||||
|
@ -50,21 +50,22 @@ class TextItem(GraphicsObject):
|
||||
self._lastTransform = None
|
||||
self._bounds = QtCore.QRectF()
|
||||
if html is None:
|
||||
self.setText(text, color)
|
||||
self.setColor(color)
|
||||
self.setText(text)
|
||||
else:
|
||||
self.setHtml(html)
|
||||
self.fill = fn.mkBrush(fill)
|
||||
self.border = fn.mkPen(border)
|
||||
self.setAngle(angle)
|
||||
|
||||
def setText(self, text, color=(200,200,200)):
|
||||
def setText(self, text, color=None):
|
||||
"""
|
||||
Set the text and color of this item.
|
||||
Set the text of this item.
|
||||
|
||||
This method sets the plain text of the item; see also setHtml().
|
||||
"""
|
||||
color = fn.mkColor(color)
|
||||
self.textItem.setDefaultTextColor(color)
|
||||
if color is not None:
|
||||
self.setColor(color)
|
||||
self.textItem.setPlainText(text)
|
||||
self.updateTextPos()
|
||||
|
||||
@ -114,6 +115,15 @@ class TextItem(GraphicsObject):
|
||||
def setAnchor(self, anchor):
|
||||
self.anchor = Point(anchor)
|
||||
self.updateTextPos()
|
||||
|
||||
def setColor(self, color):
|
||||
"""
|
||||
Set the color for this text.
|
||||
|
||||
See QtGui.QGraphicsItem.setDefaultTextColor().
|
||||
"""
|
||||
self.color = fn.mkColor(color)
|
||||
self.textItem.setDefaultTextColor(self.color)
|
||||
|
||||
def updateTextPos(self):
|
||||
# update text position to obey anchor
|
||||
@ -182,4 +192,4 @@ class TextItem(GraphicsObject):
|
||||
|
||||
self.updateTextPos()
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user