import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class EditorDelegate(QStyledItemDelegate):
def createEditor(self, parent, option, index):
if index.column() == 0:
#item = index.internalPointer()
table.insertRow(0)
table.insertRow(1)
table.insertColumn(0)
item1.setText('item1')
table.setItem(0, 0, item1)
return table
else:
return QStyledItemDelegate.createEditor(self, parent, option, index)
delegate = EditorDelegate()
tree.setItemDelegate(delegate)
item1.setText(0, 'item1')
tableChild.setText(0, 'table')
item2.setText(0, 'item2')
tableChild2.setText(0, 'table2')
tree.openPersistentEditor(tableChild)
tree.openPersistentEditor(tableChild2)
tree.show()
app.exec_()
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class EditorDelegate(QStyledItemDelegate):
def createEditor(self, parent, option, index):
if index.column() == 0:
#item = index.internalPointer()
table = QTableWidget(parent)
table.insertRow(0)
table.insertRow(1)
table.insertColumn(0)
item1 = QTableWidgetItem()
item1.setText('item1')
table.setItem(0, 0, item1)
return table
else:
return QStyledItemDelegate.createEditor(self, parent, option, index)
app = QApplication(sys.argv)
delegate = EditorDelegate()
tree = QTreeWidget()
tree.setItemDelegate(delegate)
item1 = QTreeWidgetItem(tree)
item1.setText(0, 'item1')
tableChild = QTreeWidgetItem(item1)
tableChild.setText(0, 'table')
item2 = QTreeWidgetItem(item1)
item2.setText(0, 'item2')
tableChild2 = QTreeWidgetItem(item2)
tableChild2.setText(0, 'table2')
tree.openPersistentEditor(tableChild)
tree.openPersistentEditor(tableChild2)
tree.show()
app.exec_()
To copy to clipboard, switch view to plain text mode
Bookmarks