[SOLVED] QTableView how to limit shown rows
-
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
-
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").
-
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.
-
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
-
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 :/