Select first row in QTableView after selected item is deleted.
-
I have the following problem: I have a TableView with data from a proxy model and as long as the model contains some data element - I want that one element is always selected. So when I delete the selected element for example, I'd like the first element int the TableView to get automatically selected.
I tried the following options:1.:
@TableView->slectionModel()->setCurrentIndex ( pProxyModel->index(0, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows);@- :
@TableView->selectRow(0);@
None of both did work, although the selection mode is QAbstractItemView::SingleSelection and the selection behaviour is QAbstractItemView::SelectRows before the operation.
Any ideas why this does not work?
- :
-
Unfortunatly this is no solution to me. There is no way to set up a "simple" complete application in a few minutes.
I looked for someone who maybe had already had the same problem with QItemSelectionModel in Views.
From further investigation I can say that the line gets selected correctly, but the selection is not painted. -
[quote author="sliver" date="1294997174"]
From further investigation I can say that the line gets selected correctly, but the selection is not painted.[/quote]
Now that is interesting! Sounds like a subtle bug.
Could you tell us at which point you change the selection exactly? In response to what signal or event?I am with Volker on this one. I understand that it can be hard to create an example, but it really is the best way to ferret out issues like this. It is sometimes easiest not to rip out your existing code, but to write a small example from scratch. Last time I tried that, my example actually worked, and I managed to find the issue in my main code before posting the example I created. I think something based on QStandardItemModel or the likes might work?
-
[quote author="sliver" date="1294997174"]Unfortunatly this is no solution to me. There is no way to set up a "simple" complete application in a few minutes.
I looked for someone who maybe had already had the same problem with QItemSelectionModel in Views.
From further investigation I can say that the line gets selected correctly, but the selection is not painted.[/quote]If the problem only appears in the case you select a line manually, try to create a simple example with a view and a QStandardItemModel. On a button click, select the lines.
If it's really a bug, it should also appear there, and then you have your simple example.