[PyQt] Cannot get data to be fetched by QTableView through QAbstractTableModel

Bjorn Egil Ludvigsen bludvigsen at gmail.com
Fri Apr 23 14:36:22 BST 2010


Hi,

I cannot get any data to be shown in my QTableView and wonder now if
something could be wrong with returning the QVariants(), as someone on
Daniweb said this is not necessary anymore after PyQt 4.6. Also I read the
PyQt documentation about QVariant, but have not gotten any further.

Without giving you the whole nine yards, can anyone spot any beginners error
below? The data itself is loaded into a list (self.uncertainties) of
Uncertainty() objects. An Uncertainty() has 22 attributes that I want to
show in a table. I already have a working system using QTableWidgets, so the
underlying data structures are loaded into memory and in good condition.:

(name, description, valuetype, active, defaultvalue, uuid, digits,
distribution, expectation, expression, gridsize, levels, lowerlimit,
priorweight, replacestring, standarddeviation, startvalue, stepsize,
targetfiles, category, frequency, upperlimit) = range(22)
.
.
.
class UncertaintyTableModel(QAbstractTableModel):
    def __init__(self, parent=None):
        super(UncertaintyTableModel, self).__init__(parent)
        self.uncertainties = []
.
.
.
    def data(self, index, role=Qt.DisplayRole):
        if not index.isValid() or \
            not (0 <= index.row() < len(self.uncertainties)):
            return QVariant()
        uncertainty = self.uncertainties[index.row()]
        column = index.column()
        if role==Qt.DisplayRole:
            if column == name:
                return QVariant(uncertainty.name)
            elif column == description:
                return QVariant(uncertainty.description)
.
.
.
        return QVariant()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100423/760e7b4e/attachment.html>


More information about the PyQt mailing list