本文整理汇总了Python中AnyQt.QtCore.QItemSelection.merge方法的典型用法代码示例。如果您正苦于以下问题:Python QItemSelection.merge方法的具体用法?Python QItemSelection.merge怎么用?Python QItemSelection.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtCore.QItemSelection
的用法示例。
在下文中一共展示了QItemSelection.merge方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: select
# 需要导入模块: from AnyQt.QtCore import QItemSelection [as 别名]
# 或者: from AnyQt.QtCore.QItemSelection import merge [as 别名]
def select(self, selection, flags):
"""Reimplemented."""
if isinstance(selection, QModelIndex):
selection = QItemSelection(selection, selection)
if not self.__selectBlocks:
super().select(selection, flags)
return
model = self.model()
def to_ranges(spans):
return list(range(*r) for r in spans)
if flags & QItemSelectionModel.Current: # no current selection support
flags &= ~QItemSelectionModel.Current
if flags & QItemSelectionModel.Toggle: # no toggle support either
flags &= ~QItemSelectionModel.Toggle
flags |= QItemSelectionModel.Select
if flags == QItemSelectionModel.ClearAndSelect:
# extend selection ranges in `selection` to span all row/columns
sel_rows = selection_rows(selection)
sel_cols = selection_columns(selection)
selection = QItemSelection()
for row_range, col_range in \
itertools.product(to_ranges(sel_rows), to_ranges(sel_cols)):
selection.select(
model.index(row_range.start, col_range.start),
model.index(row_range.stop - 1, col_range.stop - 1)
)
elif flags & (QItemSelectionModel.Select |
QItemSelectionModel.Deselect):
# extend all selection ranges in `selection` with the full current
# row/col spans
rows, cols = selection_blocks(self.selection())
sel_rows = selection_rows(selection)
sel_cols = selection_columns(selection)
ext_selection = QItemSelection()
for row_range, col_range in \
itertools.product(to_ranges(rows), to_ranges(sel_cols)):
ext_selection.select(
model.index(row_range.start, col_range.start),
model.index(row_range.stop - 1, col_range.stop - 1)
)
for row_range, col_range in \
itertools.product(to_ranges(sel_rows), to_ranges(cols)):
ext_selection.select(
model.index(row_range.start, col_range.start),
model.index(row_range.stop - 1, col_range.stop - 1)
)
selection.merge(ext_selection, QItemSelectionModel.Select)
super().select(selection, flags)