<HTML>
<HEAD>
<TITLE>Re: [PyQt] How can I capture some mouse events but ignore others?</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Hmm, that is what I would have thought, you could always try calling the table widget directory in the case of ignores. &nbsp;Actually, I&#8217;ll bet you have to do this since you have overridden the mousePressEvent function.<BR>
<BR>
QtGui.QTableWidget.mousePressEvent(event)<BR>
<BR>
<BR>
On 3/6/09 10:47 AM, &quot;Marc Nations&quot; &lt;<a href="mnations.lists@gmail.com">mnations.lists@gmail.com</a>&gt; wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Thanks, wasn't aware of being able to accept events.<BR>
<BR>
So I tried this, instead of waiting for release I moved it up to when a button is pressed to get a better idea of what was happening. I tried this:<BR>
<BR>
    def mousePressEvent(self, event):<BR>
        if event.button() == QtCore.Qt.RightButton:<BR>
            event.accept()<BR>
            self.rightClickMenu(event)<BR>
        else:<BR>
            event.ignore()<BR>
<BR>
According to the docs for the mouse events it should do this: &quot;You should call ignore &lt;<a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qevent.html#ignore">http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qevent.html#ignore</a>&gt; () if the mouse event is not handled by your widget. A mouse event is propagated up the parent widget chain until a widget accepts it with accept &lt;<a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qevent.html#accept">http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qevent.html#accept</a>&gt; (), or an event filter consumes it.&quot;<BR>
<BR>
My understanding of that is once I ignore the event it should automatically try the base class, which in this case is the base table widget. However using that code the left-click is basically disabled and nothing happens. So the event just seems to get dropped at that point. Is there something else I need to do to make the event retreat in the right direction?<BR>
<BR>
<BR>
<BR>
<BR>
On Fri, Mar 6, 2009 at 9:19 AM, Brian Kelley &lt;<a href="kelley@eyesopen.com">kelley@eyesopen.com</a>&gt; wrote:<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>It looks like you are not accepting the event, try:<BR>
<BR>
<BR>
if event.button() == QtCore.Qt.RightButton:<BR>
   self.rightClickMenu(event)<BR>
   event.accept()<BR>
<BR>
>From the docs:<BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Times, Times New Roman"><SPAN STYLE='font-size:14pt'><B>void QEvent::accept ()<BR>
</B></SPAN></FONT></FONT><FONT FACE="Times, Times New Roman"><SPAN STYLE='font-size:12pt'><BR>
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).<BR>
<BR>
Setting the accept parameter indicates that the event receiver wants the event. Unwanted events might be propagated to the parent widget.<BR>
<BR>
See al<FONT COLOR="#174FAF">so ign</FONT>ore().<BR>
<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>- Show quoted text -<BR>
<BR>
On 3/6/09 9:53 AM, &quot;Marc Nations&quot; &lt;<a href="mnations.lists@gmail.com">mnations.lists@gmail.com</a> &lt;<a href="http://mnations.lists@gmail.com">http://mnations.lists@gmail.com</a>&gt; &gt; wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Hi,<BR>
<BR>
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:<BR>
<BR>
class Table(QtGui.QTableWidget):<BR>
    def __init__(self, parent,  gui):<BR>
        QtGui.QTableWidget.__init__(self, parent)<BR>
        self.gui = gui<BR>
<BR>
    def mouseReleaseEvent(self, event):<BR>
        if event.button() == QtCore.Qt.RightButton:<BR>
            self.rightClickMenu(event)<BR>
            <BR>
    <BR>
    def rightClickMenu(self,  event):<BR>
        pos = event.pos<BR>
        self.gui.ui.menuEdit.popup(QtGui.QCursor.pos())<BR>
<BR>
<BR>
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 &lt;shift&gt; mode and all previous selections are kept. I can't figure out a way to turn that off.<BR>
<BR>
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.<BR>
<BR>
Thanks,<BR>
Marc<BR>
<BR>
</SPAN></FONT></BLOCKQUOTE></BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT></BLOCKQUOTE>
</BODY>
</HTML>