Python PyQt4-在QListView中的项目上按Enter键
嘿。 我有一个QListView,到目前为止,我只知道如何使用已经给出的信号。在列表(QStandardListItem)中的项目上按enter键时,我找不到任何信号。似乎也找不到任何按键事件 是否可以像这样将QListView“连接”到事件?怎么做?:)Python PyQt4-在QListView中的项目上按Enter键,python,qt4,pyqt4,Python,Qt4,Pyqt4,嘿。 我有一个QListView,到目前为止,我只知道如何使用已经给出的信号。在列表(QStandardListItem)中的项目上按enter键时,我找不到任何信号。似乎也找不到任何按键事件 是否可以像这样将QListView“连接”到事件?怎么做?:) 谢谢使用事件筛选:例如,在列表容器的设置UI中,执行 # the self param passed to installEventFilter indicates the object which # defines eventFilter
谢谢使用事件筛选:例如,在列表容器的设置UI中,执行
# the self param passed to installEventFilter indicates the object which
# defines eventFilter(), see below:
self.list.installEventFilter(self)
然后在该容器中定义过滤器API函数:
def eventFilter(self, watched, event):
if event.type() == QEvent.KeyPress and \
event.matches(QKeySequence.InsertParagraphSeparator):
i = self.list.currentRow()
# process enter key on row i
请注意,
InsertParagraphSeparator
是绑定到Enter键的逻辑事件。您可以使用其他捕获事件的方法,但我所展示的应该会为您指明正确的方向。使用事件筛选:例如,在列表容器的设置UI中,执行以下操作
# the self param passed to installEventFilter indicates the object which
# defines eventFilter(), see below:
self.list.installEventFilter(self)
然后在该容器中定义过滤器API函数:
def eventFilter(self, watched, event):
if event.type() == QEvent.KeyPress and \
event.matches(QKeySequence.InsertParagraphSeparator):
i = self.list.currentRow()
# process enter key on row i
请注意,InsertParagraphSeparator
是绑定到Enter键的逻辑事件。您可以使用其他方式捕捉事件,但我所展示的应该为您指出正确的方向