from PyQt4.QtCore import *
from PyQt4.QtGui import *
def __init__(self):
def parent(self, *args):
return self.p
def rowCount(self, index):
return 2
def columnCount(self, index):
return 1
def data(self, index, role) :
i, j = index.row(), index.column()
if role == Qt.DisplayRole :
return '\n'.join(["data %d"%i for i in range(1000)])
self.p = parent
return self.createIndex(row, col, 0)
def __init__(self, model) :
self.setModel(model)
#self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
def __init__(self, parent, model=None) :
super
(QWidget, self
).__init__
(parent
)
self.table = Table(TableModel())
vbox.setContentsMargins(0, 0, 0, 0)
vbox.addWidget(self.table)
self.setLayout(vbox)
self.table.resizeRowsToContents()
if __name__ == "__main__" :
import sys
dia = Frame(None)
dia.resize(400, 400)
dia.show()
a.exec_()
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class TableModel(QAbstractItemModel):
def __init__(self):
QAbstractItemModel.__init__(self)
def parent(self, *args):
return self.p
def rowCount(self, index):
return 2
def columnCount(self, index):
return 1
def data(self, index, role) :
i, j = index.row(), index.column()
if role == Qt.DisplayRole :
return '\n'.join(["data %d"%i for i in range(1000)])
def index(self, row, col, parent=QModelIndex()):
self.p = parent
return self.createIndex(row, col, 0)
class Table(QTableView) :
def __init__(self, model) :
QTableView.__init__(self)
self.setModel(model)
self.setSelectionBehavior(QAbstractItemView.SelectRows)
#self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
class Frame(QWidget) :
def __init__(self, parent, model=None) :
super(QWidget, self).__init__(parent)
self.table = Table(TableModel())
vbox = QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0)
vbox.addWidget(self.table)
self.setLayout(vbox)
self.table.resizeRowsToContents()
if __name__ == "__main__" :
import sys
a = QApplication(sys.argv)
dia = Frame(None)
dia.resize(400, 400)
dia.show()
a.exec_()
To copy to clipboard, switch view to plain text mode
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
To copy to clipboard, switch view to plain text mode
I think that is a bad practice.
Bookmarks