我在其中创建了QInputDialog并配置了事件过滤器,但我不知道如何防止它在 eventFilter(self, widget, event)
方法中关闭ESC或ENTER按钮 .
self.inDialog = QInputDialog(self)
#some config...
self.inDialog.setLabelText('')
self.nameAction.setText('&Nazwa pola głównego ✔')
self.inDialog.show()
我的事件过滤器概念:
def eventFilter(self, widget, event):
if isinstance(event, QtGui.QKeyEvent):
if event.key() == 16777220:
return False
# here I want to call super somehow?
return
值得一提的是,我正在QMainWindow类中进行所有这些操作,我将其称为QInputdialog . 我不想将QDialog子类化并手动编写所有内容 .
1 回答
如果你想避免事件发生在
QInputDialog
,你必须在过滤器中返回True
,另一方面最好使用Qt::Key来制作更易读的代码 .Update: 禁用关闭按钮: