add simple example on how to subclass RectItem for customization

This commit is contained in:
Martin Baeuml
2014-03-19 23:00:36 +01:00
parent 6b5dc54188
commit 19caf08ae1
+26
View File
@@ -0,0 +1,26 @@
from PyQt4.QtGui import QPen
from PyQt4.Qt import Qt
from sloth.items import RectItem
class CustomRectItem(RectItem):
# display values of x and y as text inside the rectangle
defaultAutoTextKeys = ['x', 'y']
def __init__(self, *args, **kwargs):
RectItem.__init__(self, *args, **kwargs)
# set drawing pen to red with width 2
self.setPen(QPen(Qt.red, 2))
LABELS = (
{
'attributes': {
'class': 'rect',
},
'inserter': 'sloth.items.RectItemInserter',
'item': CustomRectItem, # use custom rect item instead of sloth's standard item
'text': 'Rectangle',
},
)