当前位置: 首页>>代码示例>>Python>>正文


Python QAbstractItemModel.setData方法代码示例

本文整理汇总了Python中PyQt4.QtCore.QAbstractItemModel.setData方法的典型用法代码示例。如果您正苦于以下问题:Python QAbstractItemModel.setData方法的具体用法?Python QAbstractItemModel.setData怎么用?Python QAbstractItemModel.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtCore.QAbstractItemModel的用法示例。


在下文中一共展示了QAbstractItemModel.setData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setData

# 需要导入模块: from PyQt4.QtCore import QAbstractItemModel [as 别名]
# 或者: from PyQt4.QtCore.QAbstractItemModel import setData [as 别名]
 def setData(self, index, value, role):
     if not index.isValid():
         return False
     item = index.internalPointer().node()
     if role == Qt.CheckStateRole:
         # a checkbox was modified
         progress, success = value.toInt()
         item.toElement().setAttribute("percentageComplete",str(progress*50))
         # check children
         numChildren = item.childNodes().count()
         if numChildren > 0 and progress == Qt.Checked:
             for i in xrange(0,numChildren):
                 self.setData(index.child(i,0),value,role)
             self.dataChanged.emit(index,index.child(numChildren-1,0))
         if progress == Qt.Unchecked:
             self.setData(index.parent(),value,role)
             self.dataChanged.emit(index.parent(),index)
         return True
         
     elif role == Qt.EditRole:
         if index.column() == 0:
             # task desc
             item.toElement().setAttribute("subject",
                                                 unicode(value.toString()))
             self.dataChanged.emit(index,index)
             return True
             
         elif index.column() == 1:
             # task progress
             item.toElement().setAttribute("percentageComplete",
                                                     str(value.toString())) 
             self.dataChanged.emit(index,index)
             
             progress, success = value.toInt()
             if progress == 100:                
                 # if task is now completed, update children
                 # FIXME: this doesn't work and I don't understand why :(
                 numChildren = item.childNodes().count()
                 if numChildren > 0:
                     for i in xrange(0,numChildren):
                         self.setData(index.child(i,1),value,role)
                     self.dataChanged.emit(index,index.child(numChildren-1,1))
                     return True
                     
             elif progress < 100:
                 # if task is now NOT complete and parent is, update parent.
                 # this works
                 if self.data(index.parent(),Qt.CheckStateRole) == Qt.Checked:
                     parentIndex = self.index(index.parent().row(),index.column(),index.parent().parent())
                     self.setData(parentIndex,value,role)
                     self.dataChanged.emit(index.parent(),index)
                 return True
             return True
     # for everything else, do the generic thing
     return QAbstractItemModel.setData(self,index,value,role)
开发者ID:toyg,项目名称:plasmaapplets,代码行数:57,代码来源:tc_models.py

示例2: setData

# 需要导入模块: from PyQt4.QtCore import QAbstractItemModel [as 别名]
# 或者: from PyQt4.QtCore.QAbstractItemModel import setData [as 别名]
  def setData(self, index, value, role):
    """
    \reimp

    Set the data which value is `value` at index `index` with role `role`.

    \return `True` if no error occured, `False` otherwise.
    """
    if not index.isValid():
      return QVariant()
    column = index.column()
    if role == Qt.CheckStateRole:
      if column == HNAME:
        node = self.VFS.getNodeFromPointer(index.internalId())
        if value == Qt.Unchecked:
          if (long(node.this), 1) in self.checkedNodes:
            self.checkedNodes.remove((long(node.this), 1))
        else:
          self.checkedNodes.add((long(node.this) , 1))
    QAbstractItemModel.setData(self, index, value, role)
    return True
开发者ID:arxsys,项目名称:dff-api,代码行数:23,代码来源:node_list.py


注:本文中的PyQt4.QtCore.QAbstractItemModel.setData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。