The itemClicked/itemDoubleClicked signals don't appear to distinguish between left and middle mouse clicks. I want to do different things depending on the which was clicked. It appears that clicking happens on release so app.mouseButtons() reports NoButtons by the time my itemClicked()
is actually called.
While I haven't tried it yet, I'm assuming I could do some main app mouse test to store the state globally, then read it from my itemClicked()
, but this feels really convoluted and hacky, is there a better way I can't find?
[UPDATED] As suggested, I overrode the tree's mouse event. I also didn't want to bother subclassing QTreeWidget just for this, so for completeness's sake, here is what I did:
setattr(self.tree, 'middleMouse', False)
def mousePressEvent(self, event):
self.middleMouse = event.button() == QtCore.Qt.MidButton
return QtGui.QTreeWidget.mousePressEvent(self, event)
self.tree.mousePressEvent = types.MethodType(mousePressEvent, self.tree)
def itemClicked(item):
if self.tree.middleMouse:
<do something>
else:
<do another thing>
self.tree.itemClicked.connect(itemClicked)
Python is the best.