我试图在QListView上添加自定义上下文菜单,但没有成功。
我的密码被打击
class Ui_MainWindow(object):
def OpenNssetup(self):
self.window = QtWidgets.QDialog()
self.ui = Ui_nssetup()
self.ui.setupUi(self.window)
self.window.show()
def OpenDBsetup(self):
self.window = QtWidgets.QDialog()
self.ui = Ui_Connections()
self.ui.setupUi(self.window)
self.window.show()
def CloseApp(self):
sys.exit(0)
def dbconcontextmenu(self,event):
# Create a menu
contextMenu = QMenu(self)
conAct = contextMenu.addAction("Connect")
contestAct = contextMenu.addAction("Test Connection")
condiscAct = contextMenu.addAction("Disconnect")
action = contextMenu.exec_(self.mapToGlobal(event.pos()))
运行代码时出现以下错误。
Traceback (most recent call last):
File "mainwindow3.py", line 33, in dbconcontextmenu
contextMenu = QMenu(self)
TypeError: arguments did not match any overloaded call:
QMenu(parent: QWidget = None): argument 1 has unexpected type 'Ui_MainWindow'
QMenu(str, parent: QWidget = None): argument 1 has unexpected type 'Ui_MainWindow'