本文整理汇总了Python中PyQt5.QtCore.QMimeData.rows方法的典型用法代码示例。如果您正苦于以下问题:Python QMimeData.rows方法的具体用法?Python QMimeData.rows怎么用?Python QMimeData.rows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QMimeData
的用法示例。
在下文中一共展示了QMimeData.rows方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mimeData
# 需要导入模块: from PyQt5.QtCore import QMimeData [as 别名]
# 或者: from PyQt5.QtCore.QMimeData import rows [as 别名]
def mimeData(self, indexes):
"""Returns dragged data as MIME data"""
mime_data = QMimeData()
"""set MIME type"""
mime_data.setData(self.MIME_TYPE, QByteArray())
"""row index is just a pair of item parent and row number"""
row_indexes = []
for index in indexes:
item = self.itemFromIndex(index)
parent = item.parent()
if parent is None:
parent = self.invisibleRootItem()
row_indexes.append((parent, item.row()))
def copyRowWithChildren(row_index):
"""copy row and its children except for those that are in
row_indexes to avoid duplicates"""
parent, row_i = row_index
row = []
for column_i in range(parent.columnCount()):
original = parent.child(row_i, column_i)
copy = original.clone()
for child_row_i in range(original.rowCount()):
child_row_index = (original, child_row_i)
if child_row_index not in row_indexes:
child_row = copyRowWithChildren(child_row_index)
copy.appendRow(child_row)
row.append(copy)
return row
rows = []
for i in row_indexes:
"""copy not move, because these rows will be deleted automatically
after dropMimeData"""
rows.append(copyRowWithChildren(i))
"""mime_data.rows available only in the application"""
mime_data.rows = rows
return mime_data