tags:

views:

102

answers:

1

Hi everyone,

I'm trying to inherit QSqlTableModel to make data im my table display in way i need.

class TableViewModel(QSqlTableModel):

def __init__(self):
    super(TableViewModel, self).__init__()


def flags(self, modelIndex):
    if not modelIndex.isValid():
        return
    if modelIndex.column() != 1 and modelIndex.column() != 4:
        return Qt.ItemIsEnabled | Qt.ItemIsSelectable
    return Qt.ItemIsEditable | Qt.ItemIsEnabled | Qt.ItemIsSelectable

def data(self, modelIndex, role=Qt.DisplayRole):
    if not modelIndex.isValid():
        return QVariant()

    if role != Qt.DisplayRole & role != Qt.EditRole:
        return QVariant()

    return record.value(modelIndex.column())

With this code i'm only getting empty cells. Without data() function this code work perfectly, the data displayed in TableView exactly it should be.

I'm just enmeshed by getting data from QSqlTableModel. Where can i find it? Or is it just my call wrong?

Thanks in advance,

serge

+1  A: 

I'm not sure what that record.value is supposed to be (no indication in your code of where that record variable lives or how or when it's set). Anyway, for "getting data from QSqlTableModel" (whereby I assume you mean the base class you're subclassing), use

whatever = QSqlTableModel.data(self, modelIndex, role)
Alex Martelli
thanks, it helped. I tried to do it by my own, but mistaked somewhere and as the result - recursion
serge
Thanks are nice, but if this answer helped, what about accepting it? That's SO etiquette (use the checkmark-shaped icon below the number to the left of the answer you want to accept).
Alex Martelli