Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PyQt4-在QListView中的项目上按Enter键_Python_Qt4_Pyqt4 - Fatal编程技术网

Python PyQt4-在QListView中的项目上按Enter键

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

嘿。 我有一个QListView,到目前为止,我只知道如何使用已经给出的信号。在列表(QStandardListItem)中的项目上按enter键时,我找不到任何信号。似乎也找不到任何按键事件

是否可以像这样将QListView“连接”到事件?怎么做?:)


谢谢

使用事件筛选:例如,在列表容器的设置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键的逻辑事件。您可以使用其他方式捕捉事件,但我所展示的应该为您指出正确的方向