[SOLVED] QTableView how to limit shown rows
-
wrote on 9 Oct 2013, 07:59 last edited by
ok I put a qDebug into my data() function and it goes through all of the 40k rows and 15 columns.
When I resize a column it goes again through all rows and columns.
Is there a way to resize only the rows that the user can see (about 30 rows)
or make the view only show 1k rows and resize them?
Or do you know any good Tutorials that show how to create my own View, didn't found any good on the web.and thanks for the reply
-
wrote on 9 Oct 2013, 08:49 last edited by
It shouldn't be too hard to make a sub-class of QTableView. There's a handy isRowHidden function you can use to limit which rows to call the model data function. You just need to figure out where this happens in the current QTableView...
The Qt Documentation seems to be quite helpful ;-) But I've never done it myself
-
wrote on 9 Oct 2013, 09:01 last edited by
just had the same idea. hide the rows that are not in the range and show more when I scroll down or up.
But does QTableView resize only the shown rows?
When it would resize the hidden rows also, that wouldn't help me :(. -
wrote on 9 Oct 2013, 09:11 last edited by
You can try to insert a proxy model between your view and your model. With the proxy model you can filter the model in order to get the 50-100 rows that have to be shown by the view.
-
wrote on 9 Oct 2013, 10:05 last edited by
bq. insert a proxy model
Hmmm - or, just have the model check the view to see if the asked for values are visible or not. It doesn't sound very nice to me...bq. QTableView resize only the shown rows?
I'm not sure if you or I have got the wrong end of the stick here. Anyway, my point is that the QTableView class itself knows which rows/columns are visible (depending on how you resize the width/height of the rows/columns and the overall widget size) and thus only asks the model for the data it needs.Actually I'm a little suprised (but not very) that QTableModel itself doesn't do this already. And a little nervous for you that the QTableModel is quite complicated.
So, probably Tom's idea is the most pragmatic (even if it's not "right").
-
wrote on 9 Oct 2013, 12:05 last edited by
well I have to build a new filter for my table anyway. I will try it with the Proxy Model
-
wrote on 9 Oct 2013, 13:21 last edited by
I think the view can be configure to resize itself automatically.
See :
"QHeaderView::setResizeMode":http://qt-project.org/doc/qt-5.0/qtwidgets/qheaderview-compat.html#setResizeMode
"QTableView::horizontalHeader":http://qt-project.org/doc/qt-5.0/qtwidgets/qtableview.html#horizontalHeaderBy doing so, you do not have to resize the view programmatically.
-
wrote on 15 Oct 2013, 07:04 last edited by
ok i solved it now with a proxy model
Thanks for the help -
wrote on 26 May 2014, 02:34 last edited by
Tecnova,
Do you have a generic code of your solution that can be shared with me? I'm interested to do the same.
I'm using QTreeWidget to display a list of items that is queried from a server. I intend to limit it to display a maximum of 50 items. If returned list of items exceed 50, idea is to present a little navigator at the bottom of that window to allow user to click next 50-100, etc.
Seems very same to what you implement and was wondering whether you could share your solution or direct me to an example that you refer to in your implementation?
Thanks in advance.
Regards,
TTK
-
wrote on 26 May 2014, 03:49 last edited by
Sry I dont have acces to the source code anymore.
But I can tell you what I did.First of all I stoped using the QT Widget and made my own View, like you read above. Than I used the Proxy Model for filtering. The Advantage of the Proxy Model is that it is between your View(the actual data that is shown on you application) and the whole database. In the proxy model you can define what data of the database will be shown and which not.
In my task I did create my own datastructure(database) from files I did read in. So I did know the row number. In my Filter I simply did a range of 500 rows. Than I did overwride the keyboard buttons up and down to load the next/previous 500 rows, simply by setting the minrow and maxrow +/- 500 in my Filter. I accessed the Filter by saving his reference(pointer) when i created him. and than i simly did View.refresh() or something like that to reset the view with the new filter.
I know Views can be a bit complicated at the beginning, but they will really help you when you have to do complex things with your data.
An other oppertunity what you can do is hide every other row.
@void hideshow(int direction)
{
//not shure with that static you can also put them in a class
static int minrow = 0;
static int maxrow = 50;if(maxrow == widget.getMaxRow() || minrow == 0) // do nothing when //maxrow or minrow gets over the given data range
return;for(int i = minrow; i < maxrow; i++;)
widget.hideRow(i);switch(direction) case 1: //down minrow += 50; maxrow += 50; for(int j = minrow; j < maxrow; j++;) widget.showRow(j); break; case 2: //up minrow -= 50; maxrow -= 50; for(int j = minrow; j < maxrow; j++;) widget.showRow(j); break;
return;
}@when you want to use this code you have to hide every top level row when initialising your widget except the top 50 one. You can also override some keyboard buttons and redefine they´re meaning.
Thats all what I can help you so far. For the views you should better look up other forums or the Qt tutorials.
I hope it helps you :/ -
wrote on 26 May 2014, 04:17 last edited by
Thanks for the quick response! I'll take your advice on reading up the proxy model on filtering the data. I think the address book example in QT is quite relevant. Going through that now.
Thanks!
Regards,
TTK