[PyQt] RightClick on QListView?

Aron Bierbaum aronbierbaum at gmail.com
Mon Feb 25 19:37:55 GMT 2008


You have to use a custom context menu:

def setupUi(self):
   view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
   view.connect(view, QtCore.SIGNAL("customContextMenuRequested(QPoint)",
                        self.onContext)

def onContext(self):
      # Create a menu
      menu = QtGui.QMenu("Menu", self)
      menu.addAction(self.mAction1)
      menu.addAction(self.mAction2)
      # Show the context menu.
      menu.exec_(self.view.mapToGlobal(point))

http://doc.trolltech.com/4.3/qwidget.html#customContextMenuRequested


-Aron

On Mon, Feb 25, 2008 at 11:43 AM, Dirk Reiners <dirk at lite3d.com> wrote:
>
>         Hi All,
>
>  we're trying to have a popup menu on a QListView, but there doesn't seem to be
>  a way to detect right clicks on those. I'm sure I've done that before and there
>  was a signal, but it looks like it's gone.
>
>  Can anybody give me a hint on how to do that now?
>
>  Thanks
>
>         Dirk
>
>  _______________________________________________
>  PyQt mailing list    PyQt at riverbankcomputing.com
>  http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


More information about the PyQt mailing list