Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?
Hi,
I have a QTableView bound to a QSqlTableModel.
I'm strugling to find a way to change the row (that's the vertical) headers. Is there any way to do that? And how?
A Singer
Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?
Subclass the model and reimplement its headerData() method.
Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?
Thanks for your help. I've tried it, and works fine. However, when trying to return a QSize on role == Qt::SizeHintRole the application crashes.
Any suggestion?
Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?
It shouldn't crash (meaning your code is probably wrong) although returning a size hint role for the header has no effect as the size of the header is controlled by the size of the data cells.
Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?
Thanks. OK, as someone that tries to learn QT I will dig into the code to find out what I have done wrong. But how do I set the cell's width then?
Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?
Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?
Dear Wysota,
Thanks for the help. Before checking out on that api, I thought you might be interested in the following.
First, I found out what was causing my application to crash, and that was that I haven't provided a default return value i.e. for values that didn't match any of the tested scenarios in the headerData implementation.
Second, after fixing that bug, I found out that, returning a QSize value in the headerData implementation where role == Qt:SizeHintRole has definitely an effect on the cell size. So this one is also solved.
Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?
Quote:
Originally Posted by
Avrohom
Second, after fixing that bug, I found out that, returning a QSize value in the headerData implementation where role == Qt:SizeHintRole has definitely an effect on the cell size. So this one is also solved.
Just be aware this might be overridden by items themselves.