From 19caf08ae1fd50e87a14224e103414b5a53595df Mon Sep 17 00:00:00 2001 From: Martin Baeuml Date: Wed, 19 Mar 2014 23:00:36 +0100 Subject: [PATCH] add simple example on how to subclass RectItem for customization --- examples/customrectitemconfig.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/customrectitemconfig.py diff --git a/examples/customrectitemconfig.py b/examples/customrectitemconfig.py new file mode 100644 index 0000000..0ca5c45 --- /dev/null +++ b/examples/customrectitemconfig.py @@ -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', + }, +) +