PDA

View Full Version : Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?



Avrohom
11th May 2009, 21:06
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

wysota
11th May 2009, 22:55
Subclass the model and reimplement its headerData() method.

Avrohom
12th May 2009, 18:57
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?

wysota
12th May 2009, 19:46
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.

Avrohom
12th May 2009, 21:39
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?

wysota
12th May 2009, 22:15
Look at QHeaderView API.

Avrohom
12th May 2009, 22:41
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.

wysota
13th May 2009, 00:26
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.