单击tableView's item
将打开一个PersistentEditor
:对于第一列(因为是整数数据),它默认为QSpinBox
,对于另外两列,默认为QLineEdit
。在
onClick
我想查询已经为单击的行打开了多少个持久编辑器。在
from PyQt4 import QtCore, QtGui
app = QtGui.QApplication([])
class Model(QtCore.QAbstractTableModel):
def __init__(self):
QtCore.QAbstractTableModel.__init__(self)
self.items = [[1, 'one', 'ONE'], [2, 'two', 'TWO'], [3, 'three', 'THREE']]
def flags(self, index):
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsEditable
def rowCount(self, parent=QtCore.QModelIndex()):
return 3
def columnCount(self, parent=QtCore.QModelIndex()):
return 3
def data(self, index, role):
if not index.isValid(): return
if role in [QtCore.Qt.DisplayRole, QtCore.Qt.EditRole]:
return self.items[index.row()][index.column()]
def onClick(index):
tableView.openPersistentEditor(tableView.model().index(index.row(), index.column()))
print 'clicked index: %s'%index
tableModel=Model()
tableView=QtGui.QTableView()
tableView.setModel(tableModel)
tableView.clicked.connect(onClick)
tableView.show()
app.exec_()
QT可以提供一种方法来做你想做的事情。如果是这样的话,我想你已经看过文件了,什么也没发现。在
我想知道在您的模型上定义一个editorCount()方法是否有效,如下所示:
然后让onClick调用它:
^{pr2}$当然,理想情况下,您应该在init中定义编辑器计数字典,并且不需要在editorCount()方法本身中进行太多的异常处理。在
相关问题 更多 >
编程相关推荐