本文整理汇总了Python中PyQt5.QtWidgets.QTreeWidget.keyPressEvent方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.keyPressEvent方法的具体用法?Python QTreeWidget.keyPressEvent怎么用?Python QTreeWidget.keyPressEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.keyPressEvent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: keyPressEvent
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import keyPressEvent [as 别名]
def keyPressEvent(self, e):
if e.key() == Qt.Key_Enter or e.key() == Qt.Key_Return:
item = self.currentItem()
col = self.currentColumn()
self.editItem(item, col)
elif e.key() == Qt.Key_Left or e.key() == Qt.Key_Right:
curr_idx = self.currentIndex()
if e.key() == Qt.Key_Left:
if curr_idx.column() > 0:
next_idx = curr_idx.sibling(curr_idx.row(), curr_idx.column()-1)
self.setCurrentIndex(next_idx)
else:
if curr_idx.column() < self.colSELOPT:
next_idx = curr_idx.sibling(curr_idx.row(), curr_idx.column()+1)
self.setCurrentIndex(next_idx)
elif (e.key() == Qt.Key_Up or e.key() == Qt.Key_Down) and e.modifiers() == Qt.ControlModifier:
item = self.currentItem()
idx = self.currentIndex()
if e.key() == Qt.Key_Up:
if item.childCount():
self.collapseItem(item)
else:
if item.parent():
self.collapseItem( item.parent() )
p_idx = idx.parent()
self.setCurrentIndex( p_idx.sibling( p_idx.row(), idx.column() ) )
else:
if item.childCount():
self.expandItem(item)
else:
QTreeWidget.keyPressEvent(self, e)
示例2: keyPressEvent
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import keyPressEvent [as 别名]
def keyPressEvent(self, event: QKeyEvent):
if self.window().is_dirty() \
and (event.matches(QKeySequence.MoveToNextLine) or event.matches(QKeySequence.MoveToPreviousLine)):
veto = self.window().central_widget.promptToSave()
if not veto:
QTreeWidget.keyPressEvent(self, event)
else:
event.ignore()
else:
QTreeWidget.keyPressEvent(self, event)
示例3: keyPressEvent
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import keyPressEvent [as 别名]
def keyPressEvent(self, event):
if event.key() in [ Qt.Key_F2, Qt.Key_Return ]:
self.on_activated(self.currentItem(), self.currentColumn())
else:
QTreeWidget.keyPressEvent(self, event)