Double right-click listener for a QTableWidget

后端 未结 1 536
情话喂你
情话喂你 2021-01-15 03:34

I have a PyQt5 QTableWidget for which I want to detect double-right-click events.

Here is my \'design.py\' module:

from PyQt5 import QtCore, QtWidget         


        
相关标签:
1条回答
  • 2021-01-15 03:39

    You can use an event-filter to watch for a MouseButtonDblClick event:

    class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
        def __init__(self, *args, **kwargs):
            ...
            self.tblBoxes.viewport().installEventFilter(self)
    
        def eventFilter(self, source, event):
            if (event.type() == QtCore.QEvent.MouseButtonDblClick and
                event.buttons() == QtCore.Qt.RightButton and
                source is self.tblBoxes.viewport()):
                item = self.tblBoxes.itemAt(event.pos())
                if item is not None:
                    print('dblclick:', item.row(), item.column())
            return super(MainWindow, self).eventFilter(source, event)
    
    0 讨论(0)
提交回复
热议问题