1

I have simple application which show table from sqlite database in QTableView. One column of table is for storing date. I want to provide user easy way to modify date in this column. I have reimplemented data method of QtSql.QSqlTableModel to change QVariant type to QDate:

class Model(QtSql.QSqlTableModel):
    [...]

    def data(self, index, role=QtCore.Qt.DisplayRole):
        if index.column() == 3:
            return super(Model, self).data(index, role).toDate()
        return super(Model, self).data(index, role)

    [...]

After this change I got column:

date column

But user dont have possibility to have empty date. How can I fix that?

Is it possible to have calendar popup instead of this date edit? Should I use delegate or there is other way go? If delegate is best way, how to set delegate for single QTableView column?

4

1 に答える 1

0

カスタム エディター ウィジェットを提供するには、デリゲートを使用する必要があります。QTableView::setItemDelegateForColumnメソッドはqdocを助けることができます

于 2012-11-03T12:24:24.403 に答える