[PyQt] How can I capture some mouse events but ignore others?
Brian Kelley
kelley at eyesopen.com
Fri Mar 6 15:19:11 GMT 2009
It looks like you are not accepting the event, try:
if event.button() == QtCore.Qt.RightButton:
self.rightClickMenu(event)
event.accept()
>From the docs:
void QEvent::accept ()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Setting the accept parameter indicates that the event receiver wants the event. Unwanted events might be propagated to the parent widget.
See also ignore().
On 3/6/09 9:53 AM, "Marc Nations" <mnations.lists at gmail.com> wrote:
Hi,
I'm trying to create a custom table which pops up a menu when the user right clicks. This part works ok. It looks like this:
class Table(QtGui.QTableWidget):
def __init__(self, parent, gui):
QtGui.QTableWidget.__init__(self, parent)
self.gui = gui
def mouseReleaseEvent(self, event):
if event.button() == QtCore.Qt.RightButton:
self.rightClickMenu(event)
def rightClickMenu(self, event):
pos = event.pos
self.gui.ui.menuEdit.popup(QtGui.QCursor.pos())
The problem is that the default before of left click is changed, and I can't reset it. Without the mods the left clicks acts where if a multiple selection is made then clicking on another table cell de-selects all the previous items (unless a modifier key is used). With the above method, once multiple selections are made then it basically goes into <shift> mode and all previous selections are kept. I can't figure out a way to turn that off.
Is there a way to cherry pick which mouse events you want and ignore the rest, basically letting them keep their default behavior? Because it looks like once the function is taken over then the default behaviors are lost.
Thanks,
Marc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090306/7ade34b7/attachment.html
More information about the PyQt
mailing list