I would like to set ObjectName to my LineItem
but when I use
self.line.setItemName('%d' % i)
it is not work and stop the program over there. Can someone tell me how to do? Plz
def createLineItem(self,start,end):
global i
i +=1
self.line = QGraphicsLineItem(QLineF(start, end))
print("~")
self.line.setItemName('%d' % i)
print("~~")
print( "Line",self.line.objectName())
self.scene().addItem(self.line)
First of all, where did you get that information that QGraphicsLineItem the setItemName method? QGraphicsLineItem does not have the setItemName method. On the other hand, objectName is a property of the QObjects but QGraphicsLineItem is not. An alternative to save names is to use the data method: