![]() |
傻傻的消炎药 · Machine Learning ...· 23 小时前 · |
![]() |
爱热闹的充电器 · 余敏友:“上海精神”彰显国际法新理念 - ...· 4 月前 · |
![]() |
开朗的咖啡 · 写一段java docker ...· 7 月前 · |
![]() |
爱健身的马铃薯 · 夜读丨如果有什么必须战胜的对手,那就是过去的 ...· 7 月前 · |
![]() |
打篮球的作业本 · Linen Community· 1 年前 · |
qtreewidget 索引 中国移动 |
https://cloud.tencent.cn/developer/information/%E5%A6%82%E4%BD%95%E5%9C%A8QAbstractItemView%E4%B8%AD%E7%A7%BB%E5%8A%A8QWidget%EF%BC%9F |
![]() |
爱跑步的感冒药
7 月前 |
在QAbstractItemView中移动QWidget可以通过以下步骤完成:
class CustomDelegate(QStyledItemDelegate):
def __init__(self, parent=None):
super().__init__(parent)
def createEditor(self, parent, option, index):
editor = QWidget(parent)
# 添加需要显示的部件,并进行布局
return editor
def setEditorData(self, editor, index):
# 从模型中获取数据,将数据设置到部件中显示
def setModelData(self, editor, model, index):
# 从部件中获取数据,将数据设置到模型中
def updateEditorGeometry(self, editor, option, index):
editor.setGeometry(option.rect)
class CustomView(QAbstractItemView):
def __init__(self, parent=None):
super().__init__(parent)
self.setItemDelegate(CustomDelegate(self))
def edit(self, index, trigger, event):
if index.isValid():
if trigger == QAbstractItemView.AllEditTriggers or trigger == QAbstractItemView.DoubleClicked:
self.openPersistentEditor(index)
def closeEditor(self, editor, hint):
self.closePersistentEditor(self.currentIndex())
def currentChanged(self, current, previous):
self.closeEditor(None, QAbstractItemDelegate.NoHint)
QAbstractItemView.currentChanged(self, current, previous)
def visualRect(self, index):
rect = QAbstractItemView.visualRect(self, index)
return rect
def scrollTo(self, index, hint):
QAbstractItemView.scrollTo(self, index, hint)
class CustomModel(QAbstractItemModel):
def __init__(self, parent=None):
super().__init__(parent)
self.rootItem = CustomItem("Root")
def index(self, row, column, parent):
# 返回具有给定行列索引和父索引的模型索引
def parent(self, index):
# 返回具有给定索引的模型索引的父索引
def rowCount(self, parent):
# 返回父索引下的行数
def columnCount(self, parent):
# 返回父索引下的列数
def data(self, index, role):
# 返回给定模型索引和角色的数据
def setData(self, index, value, role):
# 设置给定模型索引和角色的数据
def headerData(self, section, orientation, role):
# 返回给定部分、方向和角色的标题数据
通过上述步骤,可以在QAbstractItemView中移动QWidget。在自定义的委托类中创建自定义的QWidget部件,然后在视图中使用这个委托类来显示和编辑每个单元格的数据。在自定义的模型类中提供数据,并在视图中显示。根据实际需求,可以进一步添加逻辑和功能来满足特定的应用场景。
推荐的腾讯云相关产品:
请注意,以上推荐的腾讯云产品仅供参考,具体选择应根据实际需求和情况进行评估和决策。
![]() |
傻傻的消炎药 · Machine Learning Methods for Automatic Silent Speech Recognition Using a Wearable Graphene Strain Ga 23 小时前 |
![]() |
打篮球的作业本 · Linen Community 1 年前 |