drag-and-drop columns.
-
Of course, if possible, I just want to add hiding through the view. However, since this hiding addition will depend on the column names on the labels, the correct column information must be sent to the right place. So in this case, I think that operations should be done on the model. What do you think?
-
Of course, if possible, I just want to add hiding through the view. However, since this hiding addition will depend on the column names on the labels, the correct column information must be sent to the right place. So in this case, I think that operations should be done on the model. What do you think?
@Nevez
This is not the way to think of it. You do not arrange your base database model/table to suit what you might or might not want to show in a view. Either you want to add new columns of genuine data to the database or you do not. UPDATE Oh, I just saw you only want to hide columns, not add extra ones. Although earlier I thought you were saying you want to add columns. -
So if it is only visual adding/removing of existing columns, then QTableView's setColumnHidden is what you want to use. With that your model is not affected at all.
-
yes, this is a good method. but i am wondering if there is any way i can find out this.
For example, suppose you have a tableview with 10 columns loaded with a model.
When I hide the column in the 5.index with the "hideColumn(5)" method on this tableview,
According to the view, the index numbers of the columns after the 5th index should decrease by one.
example: (4- [5] --- 6 -7 -8 -9 -10 --->>> 4 - [hided] ---- 5 -6 -7 -8 - 9 )But I check it with visualindex method , index numbers do not changing.
but i need to do this. Because When I hide the column, the index numbers of the labels decrease by one because the label in the layout above that column is also hidden. -
yes, this is a good method. but i am wondering if there is any way i can find out this.
For example, suppose you have a tableview with 10 columns loaded with a model.
When I hide the column in the 5.index with the "hideColumn(5)" method on this tableview,
According to the view, the index numbers of the columns after the 5th index should decrease by one.
example: (4- [5] --- 6 -7 -8 -9 -10 --->>> 4 - [hided] ---- 5 -6 -7 -8 - 9 )But I check it with visualindex method , index numbers do not changing.
but i need to do this. Because When I hide the column, the index numbers of the labels decrease by one because the label in the layout above that column is also hidden.@Nevez
Hi
Maybe you can use logical index insteadhttps://uvesway.wordpress.com/2013/01/08/qheaderview-sections-visualindex-vs-logicalindex/
-
@Nevez
Hi
Maybe you can use logical index insteadhttps://uvesway.wordpress.com/2013/01/08/qheaderview-sections-visualindex-vs-logicalindex/
@mrjj said in drag-and-drop columns.:
Maybe you can use logical index instead
Not maybe - it's a must. The visual index is... a visual index so it's not reliable when trying to access the underlying data from the outside.
-
my problem is that the visual array doesn't give the result I want.
That is, the indexes of the columns to the right of the hided column do not decreasing by one.According to the link @mrjj gave , I guess for this to happen, if I delete a column from the model, The indexes to the right of the deleted column decrease by one.
This was a little bad for me. -
my problem is that the visual array doesn't give the result I want.
That is, the indexes of the columns to the right of the hided column do not decreasing by one.According to the link @mrjj gave , I guess for this to happen, if I delete a column from the model, The indexes to the right of the deleted column decrease by one.
This was a little bad for me.@Nevez
Perhaps you need to give a tiny example illustrating what you claim. Although I haven't used visual indexes, I would expect that after hiding a column the column(s) to the right would have visual indexes one less than the model indexes they show. Note that the model indexes will not change in any way: normally the visual index is the same as the model index, but once you hide a column they will differ. Is that not what you find, or not what your expectation is? -
@JonB said in drag-and-drop columns.:
I would expect that after hiding a column the column(s) to the right would have visual indexes one less than the model indexes they show.
Unfortunately, I tested it, it does not decrease.
@JonB said in drag-and-drop columns.:
normally the visual index is the same as the model index, but once you hide a column they will differ.
No, as I said, when we hide the column, the visual index numbers still do not change (unless we move the columns). So the model index is the same as the visual index.
-
@JonB said in drag-and-drop columns.:
I would expect that after hiding a column the column(s) to the right would have visual indexes one less than the model indexes they show.
Unfortunately, I tested it, it does not decrease.
@JonB said in drag-and-drop columns.:
normally the visual index is the same as the model index, but once you hide a column they will differ.
No, as I said, when we hide the column, the visual index numbers still do not change (unless we move the columns). So the model index is the same as the visual index.
@Nevez
OK, I've had a search. This was covered in the https://uvesway.wordpress.com/2013/01/08/qheaderview-sections-visualindex-vs-logicalindex/ reference @mrjj gave you, did you read it?Visual indexes tell us the current position that a given section occupies in the header.
However there is a detail one has to be aware of: hiding/showing a given section (calling QHeaderView.hideSection method) does NOT change its visual index as one could expect.
So it's perfectly clear: visual indexes are for when you re-order the view columns, but if you only hide a column it (and subsequent columns) still retain their index into the header columns.
As I say, I haven't used visual indexes/hiding of columns. But if there is not some better way you would need to write code to map from on-screen-visible columns to underlying column numbers by taking into account which column(s) are hidden where. Which is just some code to write.