[solved]why table header is not displayed?

  • I subclassed a model from QAbstracTableModel. When I was in debug mode, the breakpoints I set in the Headerdata() function is reached, but there is no header displayed in the table. No problem with data(...), data are displayed correctly. thanks for help.

    ** ok, looks like I should not return QString("ccc") when it is not in display role.

    @class steptablemodel : public QAbstractTableModel
    explicit steptablemodel(QObject *parent = 0);
    void setStepTable(QStringList &tablelist);
    int rowCount(const QModelIndex &parent) const;
    int columnCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const;

    public slots:

    QStringList stepTable;

    QVariant steptablemodel::headerData(int section, Qt::Orientation orientation, int role) const
    if (role != Qt::DisplayRole)
    return QString("ccc");
    return QVariant("aaa");

    QVariant steptablemodel::data(const QModelIndex &index, int role) const
    if (!index.isValid()) return QVariant();

    if(index.row() >= stepTable.size() || index.row() < 0)
        return QVariant();
    if (role == Qt::DisplayRole) {
        return stepTable.at(index.row()*columnCount(index)+index.column());
    return QVariant();


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.