from PyQt4 import QtCore,QtGui
import sys
spl.
addWidget(QtGui.
QLabel('Filler'))
# create table
def __init__(self):
super(tbl,self).__init__()
self.setRowCount(20)
self.setColumnCount(2)
self.horizontalHeader().setStretchLastSection(False)
self.
horizontalHeader().
setResizeMode(QtGui.
QHeaderView.
ResizeToContents) self.
verticalHeader().
setResizeMode(QtGui.
QHeaderView.
ResizeToContents) self.setItemDelegate(delg(self))
# persist editors
for x in xrange(0,self.rowCount()):
for y in xrange(0,self.columnCount()):
for x in xrange(0,self.rowCount()):
for y in xrange(0,self.columnCount()):
self.openPersistentEditor(self.item(x,y))
self.resizeColumnsToContents()
# create item delegate
def __init__(self,parent):
super(delg,self).__init__(parent)
def createEditor(self,parent,option,index):
if index.column() == 1:
if index.row() == 15:
t.setRowCount(5)
t.setColumnCount(50)
return t
t = tbl()
spl.addWidget(t)
mw.setCentralWidget(spl)
# add and show
mw.show()
sys.exit(app.exec_())
from PyQt4 import QtCore,QtGui
import sys
app = QtGui.QApplication(sys.argv)
mw = QtGui.QMainWindow()
spl = QtGui.QSplitter()
spl.addWidget(QtGui.QLabel('Filler'))
# create table
class tbl(QtGui.QTableWidget):
def __init__(self):
super(tbl,self).__init__()
self.setRowCount(20)
self.setColumnCount(2)
self.horizontalHeader().setStretchLastSection(False)
self.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents)
self.verticalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents)
self.setItemDelegate(delg(self))
# persist editors
for x in xrange(0,self.rowCount()):
for y in xrange(0,self.columnCount()):
self.setItem(x,y,QtGui.QTableWidgetItem('test'))
for x in xrange(0,self.rowCount()):
for y in xrange(0,self.columnCount()):
self.openPersistentEditor(self.item(x,y))
self.resizeColumnsToContents()
# create item delegate
class delg(QtGui.QItemDelegate):
def __init__(self,parent):
super(delg,self).__init__(parent)
def createEditor(self,parent,option,index):
if index.column() == 1:
return QtGui.QLineEdit(parent=parent)
if index.row() == 15:
t = QtGui.QTableWidget(parent=parent)
t.setRowCount(5)
t.setColumnCount(50)
return t
return QtGui.QLineEdit(parent=parent)
t = tbl()
spl.addWidget(t)
mw.setCentralWidget(spl)
# add and show
mw.show()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
Bookmarks