Hi,

I think these are bugs but I'm not sure, so, in case I'm doing something
wrong, I'm emailing first.  I am using Python 2.7.2, PySide 1.0.5, Qt 4.7.3,
and ArchLinux with kernel 3.0.3.

I'm porting an application from PyQt4, and the code works as intended
there.  I'm trying to create a table by subclassing QAbstractTableModel and
using QTableView.  When I minimally implement QAbstractTableModel (just
implementing rowCount, columnCount, data, headerData, and flags) the
resulting table is not how I would expect it to look (again, based on my
experiences with PyQt4).

First, each cell has a checkbox in it, even though I have not requested that
the cells be checkable, nor is the data boolean values.  I cannot find any
setCheckable-like method to use with the model or view, and flags() never
includes Qt.ItemIsUserCheckable.

Second, if I call resizeColumnsToContents and resizeRowsToContents, then the
columns and rows are resized to  the checkboxes and headers that are
displayed (even though I don't want checkboxes). However, the cell data,
even if it is very long, is not considered during the resize. Since the
headers are displayed, I can resize the rows and see that there is data to
the right of the checkboxes. Shouldn't the resize methods also consider the
cell contents?

If I use a QStandardItemModel instead of subclass a QAbstractTableModel,
then none of these problems appear. I'm not sure what goes into the
QStandardItemModel, however; perhaps it is calling some methods that I
should be calling during __init__?

I have attached a file that shows these two things when run as python2
table.py

Thanks in advance for any help with these issues, and great work with PySide
so far!

Ben
from PySide.QtGui import *
from PySide.QtCore import *
import sys, signal

class Table(QAbstractTableModel):
    def __init__(self, *args):
        QAbstractTableModel.__init__(self, *args)
        self.d = [[1,2],[3,4]]
    def rowCount(self, parent = QModelIndex()):
        return 2
    def columnCount(self, parent = QModelIndex()):
        return 2
    def data(self, index, role = Qt.DisplayRole):
        return self.d[index.row()][index.column()]
    def headerData(self, section, orientation, role):
        if role == Qt.DisplayRole:
            return 'head'
    def flags(self, index):
        return Qt.ItemIsEditable | Qt.ItemIsEnabled

signal.signal(signal.SIGINT, signal.SIG_DFL)
q =QApplication(sys.argv)
w = QWidget()
w.resize(400,400)
q.window = w

t=QTableView(w)
m = Table()
t.setModel(m)
t.resizeColumnsToContents()
t.resizeRowsToContents()

w.show()
sys.exit(q.exec_())

_______________________________________________
PySide mailing list
PySide@lists.pyside.org
http://lists.pyside.org/listinfo/pyside

Reply via email to