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. QSqlTableModel - how to change row headers?
Forum Updated to NodeBB v4.3 + New Features

QSqlTableModel - how to change row headers?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 288 Views
  • 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.
  • M Offline
    M Offline
    Mnemonic
    wrote on last edited by
    #1

    Hello,

    I'd like to change row headers in QSqlTableModel, in case of QStandardItemModel this line works fine:

    model->setHeaderData(model->rowCount() - 1, Qt::Vertical, value);
    

    But for QSql nothing happens. How to solve it? How to design solution in case of necessary omit an issue? I'm using OnFieldChange strategy and Qt 5.12.

    JonBJ 1 Reply Last reply
    0
    • M Mnemonic

      Hello,

      I'd like to change row headers in QSqlTableModel, in case of QStandardItemModel this line works fine:

      model->setHeaderData(model->rowCount() - 1, Qt::Vertical, value);
      

      But for QSql nothing happens. How to solve it? How to design solution in case of necessary omit an issue? I'm using OnFieldChange strategy and Qt 5.12.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Mnemonic

      • Verify what model->rowCount() is at the time you call it --- might not be what you expect.
      • Try model->setHeaderData(0, Qt::Horizontal, "Test"); to verify that works. Is the issue then with Qt::Vertical only?
      • Try sub-classing and overriding QVariant QSqlTableModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const, does that work? (Maybe have a look at old post at https://www.qtcentre.org/threads/15328-setHeaderData-Qt-Vertical-on-QSqlTableModel .)

      I suspect (not sure) the issue is that setHeaderData(Qt::Vertical) has somewhere to store your value in a QStandardItemModel but not in a QSqlTableModel. The last suggestion may address that.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mnemonic
        wrote on last edited by Mnemonic
        #3

        Calling method with constant values doesn't help. I read that method is not working in general for QSqlTableModel.
        I have tried to override method which you mentioned. Indeed it works, but it returns separately all row headers every time when I insert new record to the model. I present working day number and currently calculation this require using class private variable. I cannot do this with const at the end of method. Maybe I should try to implement my logic in another way... but is there any chance of getting another simpler idea? I'm not professional c++ programmer, so I'll be grateful for help. Thanks.

        Edit: It seems that no one have other ideas, In the meantime I reimplemented calculating method for filing row headers data.
        Thank you JonB for help!

        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