Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]why table header is not displayed?
Forum Updated to NodeBB v4.3 + New Features

[solved]why table header is not displayed?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 686 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shalongbasi
    wrote on last edited by
    #1

    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
    {
    Q_OBJECT
    public:
    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;
    signals:

    public slots:

    private:
    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();
    

    }
    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved