#QListView控件多选设置self.ui.listView.setSelectionMode(QAbstractItemView.ExtendedSelection)
#初始化QListView控件焦点事件
self.ui.listView.installEventFilter(self)
#焦点响应事件
def eventFilter(self, widget, event):
#失去焦点 if event.type() == QtCore.QEvent.FocusOut: print ‘focus out‘ #注意要有返回值 不然会出 TypeError: invalid result type from mouseoverEvent.eventFilter() return False
#获得焦点 if event.type()==QtCore.QEvent.FocusIn: print ‘focus in‘ return False else: # we don‘t care about other events return False
时间: 2024-12-19 16:25:09