Add dropdown actions to Pyqt5 frame widget when right-click event is triggered
01:54 13 Mar 2023

I have a QFrame widget, and I already created an event trigger like this

    def mousePressEvent(self, QMouseEvent):
        if QMouseEvent.button() == Qt.RightButton:
            # do what you want here
            print("Right Button Clicked")
            #showMenuAtMouseLocation()  # to be implemented

I want a small menu list to be added at the mouse location (on the widget), which contains some actions, as in the image.

I tried adding a QMenu to the frame widget, but it doesn't show

class TOCFrame(QFrame):
    def __int__(self):
        QFrame.__int__(self)
        self.menuBar = QMenuBar(self)
        exitMenu = self.menuBar.addMenu('remove')
        self.menuBar.show()

    def mousePressEvent(self, QMouseEvent):
        if QMouseEvent.button() == Qt.RightButton:
            # do what you want here
            print("Right Button Clicked")
            #showMenuAtMouseLocation()  # to be implemented

python user-interface pyqt5 qt5