January 13, 2011

sliver sliver
Lab Rat
8 posts

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.:

  1. TableView->slectionModel()->setCurrentIndex ( pProxyModel->index(0, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows);

2. :

  1. 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?

 Signature 

sliver

6 replies

January 13, 2011

Volker Volker
Robot Herder
5428 posts

you must

  1. view->setSelectionBehavior(QAbstractItemView::SelectRows);
  2. view->setSelectionMode(QTableView::SingleSelection);

Did you call the first one?

January 13, 2011

sliver sliver
Lab Rat
8 posts

no, but the debug output said that this is already the case. These attributes are already set correctly in the ui-File.

 Signature 

sliver

January 13, 2011

Volker Volker
Robot Herder
5428 posts

Time to setup a small, complete application so that we can have a look at it.

January 14, 2011

sliver sliver
Lab Rat
8 posts

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.

 Signature 

sliver

January 14, 2011

Andre Andre
Area 51 Engineer
6031 posts

sliver wrote:

From further investigation I can say that the line gets selected correctly, but the selection is not painted.

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?

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

January 14, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts
sliver wrote:
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.

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.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

 
  ‹‹ How to let column’s width fit to the window’s width in QTableView?      Crash when using QTextFormat::FullWidthSelection with word wrap ››

You must log in to post a reply. Not a member yet? Register here!