PDA

View Full Version : [QTableView] change data position if table resizes



Schluchti
3rd March 2014, 09:56
Hi,

I have a question regarding the model/view concept of Qt. Let's assume, I fetch 30 rows from a database and I want to display them in a QTableView. Due to the size of the QTableView, only 10 rows are visible at a time. If the user wants to see the other rows, he has to scroll vertically. So what I get is this:


1.row
2.row
3.row
.
.
.
.
30.row

Instead of displaying the data in one column (where the user has to scroll vertically), I now want to display as many items as possible in one column and then move on to the next column (so that the user has to scroll horizontally). So what I want is this:


1.row 11.row 21.row
2.row 12.row .
3.row 13.row .
4.row .
5.row .
6.row .
7.row
8.row
9.row
10.row 20.row 30.row

What's the best way to accomplish this with Qt?

I know that I can calculate the number of items which can be shown in one column (this is the viewport height divided by the row height), but the model doesn't know anything about the dimension of the table. I thought about re-ordering the data (i.e adapting the model's data() method) every time the resizeEvent of the table get's called, but is there a more elegant solution to this problem?

Kind Regards
Bernhard

anda_skoa
3rd March 2014, 14:51
Hmm. Maybe use a QListView, IconMode, flow TopToBottom

Cheers,
_