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. Can't setHeaderData in class derived from QAbstractTableModel[SOLVED]

Can't setHeaderData in class derived from QAbstractTableModel[SOLVED]

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.1k Views 2 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.
  • R Offline
    R Offline
    Roma_12
    wrote on last edited by Roma_12
    #1

    Hello again.

    I tried to create my own model derived from QAbstractTableModel. I have inherited it like that:

    class MyTableModel: public QAbstractTableModel {
    ....
    public:
        int rowCount(const QModelIndex& index) const;
        int columnCount(const QModelIndex& index) const { return 2; }
        QVariant data(const QModelIndex & index, int role) const;
    ....
    }
    

    My model is working fine except I can't change the header of row:

    MyTableModel model;
    bool is_change = model.setHeaderData(0, Qt::Horizontal, "Column1");
    qDebug() << is_change;
    

    All time in console I see "false".
    Also I tried reimplement this method with calling headerDataChanged(), but the false answer still exists.

    Please, help me to change header data)
    Thank you

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Maybe a silly question but: do you have at least one column in your model ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Maybe a silly question but: do you have at least one column in your model ?

        R Offline
        R Offline
        Roma_12
        wrote on last edited by
        #3

        @SGaist
        No. So I can set Header Name only after I have create first row?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          AFAIK, you can't set a header on a row/column that doesn't exist. The row/column can be empty, but it still needs to exist

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply
          0
          • SGaistS SGaist

            AFAIK, you can't set a header on a row/column that doesn't exist. The row/column can be empty, but it still needs to exist

            R Offline
            R Offline
            Roma_12
            wrote on last edited by Roma_12
            #5

            @SGaist

            Sorry.
            I understood my mistake.
            The point is that I have done mistake in my previous code.
            I have two columns(not two rows) and trying to specify one of them.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Roma_12
              wrote on last edited by
              #6

              It's again me.
              The only thing which I needed to do - to reimplement this method :

              QVariant QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role) const.
              

              Thanks

              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