QSqlTableModel - how to change row headers?
-
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.
-
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.
- 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 withQt::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 aQStandardItemModel
but not in aQSqlTableModel
. The last suggestion may address that. - Verify what
-
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!