How can I write append mouse click coordinates to a QTableWidget
with each click? I already have the QMouseEvent
to display the coordinates in a QLabelItem
, but I would like to add a row with the coordinates of each click. Is this possible? I know I would need to use setItem()
but how do I attach this to the existing mouse click event?
Here's the event filter that I have for the mouse clicks:
def eventFilter(self, obj, event):
if obj is self.p1 and event.type() == event.GraphicsSceneMousePress:
if event.button()==Qt.LeftButton:
pos=event.scenePos()
x=((pos.x()*(2.486/96))-1)
y=(pos.y()*(10.28/512))
self.label.setText("x=%0.01f,y=%0.01f" %(x,y))
#here is where I get lost with creating an iterator to append to the table with each click
for row in range(10):
for column in range(2):
self.coordinates.setItem(row,column,(x,y))