QTableView default selection
-
wrote on 18 Jun 2018, 04:29 last edited by
By default, how to select the first row in QTableView with QFileSystemModel? When i use
table->selectRow(0)
it selects nothing, when i useQObject::connect(model, &QFileSystemModel::directoryLoaded, [&]{table->selectRow(0);});
it selects fourth row.
But if i usetable->selectRow(0)
in events (void keyPressEvent(QKeyEvent *event)
for example), it works ok, what is the problem? -
Hi,
Did you check the path returned by
directoryLoaded
? Is it the one you expect ?In any case, I'd use the model's index method to get the row corresponding to the loaded path.
-
wrote on 18 Jun 2018, 07:43 last edited by
table->selectionModel()->select(table->model()->index(0,0),QItemSelectionModel::ClearAndSelect);
-
Hi,
Did you check the path returned by
directoryLoaded
? Is it the one you expect ?In any case, I'd use the model's index method to get the row corresponding to the loaded path.
-
It's given in parameter of the 'directoryLoaded' signal.
-
wrote on 20 Jun 2018, 00:55 last edited by nammiddThis post is deleted!
-
wrote on 20 Jun 2018, 14:32 last edited by nammidd
The problem is solved, it seems that QTableView performs sorting after directory loaded.
Is there a way to prevent sorting? -
The problem is solved, it seems that QTableView performs sorting after directory loaded.
Is there a way to prevent sorting?wrote on 20 Jun 2018, 18:27 last edited by -
The problem is solved, it seems that QTableView performs sorting after directory loaded.
Is there a way to prevent sorting?wrote on 21 Jun 2018, 04:14 last edited by -
wrote on 21 Jun 2018, 04:51 last edited by
@Prince_0912
@nammidd said in QTableView default selection:@JonB This option only allows to change sorting order (from ascending to descending or vice versa), by clicking on the column header. But the sorting is done anyway, regardless of whether the option is turned on or off.
7/11