QTableView clicked() versus doubleClicked()
-
To answer my own question! This seems to work:
void StackingDlg::tableView_selectionChanged([[maybe_unused]] const QItemSelection& selected, [[maybe_unused]] const QItemSelection& deselected) { QItemSelectionModel * qsm = ui->tableView->selectionModel(); QModelIndexList selectedRows = qsm->selectedRows(); qDebug() << "Number of selected rows: " << selectedRows.count(); // // If only one row is selected, we want to know the filename // if (1 == selectedRows.count()) { QModelIndex& ndx = selectedRows[0]; qDebug() << " Selected row: " << ndx.row();though there's one remaining oddity.
When I click on the single row, the row is highlighted to show it's selected, and the image loading is started in another thread, and the table view is disabled.
On completion of the loading, the table view is enabled again, but the highlight is lost until I click on somewhere else in the window (not the rows of the tableview).
I changed that code to NOT disable the table view and the highlight did not go away.
Is there a way to prevent USER interaction with a control but allow internal events to continue processing?
@Perdrix said in QTableView clicked() versus doubleClicked():
and the image loading is started in another thread, and the table view is disabled.
Just asking: do you really need a separate thread for this "image loading" and having this "disabling" and consequent "focus losing"? Maybe you do, but have you tried without bothering?
-
@Perdrix said in QTableView clicked() versus doubleClicked():
and the image loading is started in another thread, and the table view is disabled.
Just asking: do you really need a separate thread for this "image loading" and having this "disabling" and consequent "focus losing"? Maybe you do, but have you tried without bothering?
-
@Perdrix said in QTableView clicked() versus doubleClicked():
the table view is enabled again, but the highlight is lost
Because the table lost the focus, set it again with:
tableView->setFocus(Qt::OtherFocusReason); -
@Perdrix said in QTableView clicked() versus doubleClicked():
it can take quite a while for some of these images.
Just because I am interested: do you mean (it takes much time) to load the image (once generated if that is what you are doing) into the UI, or do you mean to generate an image to load?
-
Do you want to show the full image size ?
Otherwise creating a cache with small versions of them might be a better solution in terms of speed and only load the real version when really needed. -
Hence my suggestion, have a "pre-processing" phase where you create thumbnails to show quickly and load the complete file in the background. Once it's done notify your application and do what you need with it.
-
No I can't do thumbnails as I don't know a-priori what files are involved and there might be 100s of them.
Now back to the problem - selectionChanged works fine to detect the newly selected row to trigger image loading.
Unfortunately, double clicking on a editable cell still results in selectionChanged driving the image loading to start.
What it doesn't do is open the editor on the cell that was double clicked!
I had a quick look at the code of mouseDoubleClickEvent in QAbstractItemView.cpp, and I think it is written so that it should always open the editor. I suspect that the way mousePressedEvent() is written means that the double click event isn't generated if the selection change is driven from there (I don't think it should be driven from there - rather it should be driven from a mouseClickedEvent()) which isn't present. I do see code in mousPressedEvent() that is intended to open the editor, but don't quite "get" why that wasn't invoked.
David
-
No I can't do thumbnails as I don't know a-priori what files are involved and there might be 100s of them.
Now back to the problem - selectionChanged works fine to detect the newly selected row to trigger image loading.
Unfortunately, double clicking on a editable cell still results in selectionChanged driving the image loading to start.
What it doesn't do is open the editor on the cell that was double clicked!
I had a quick look at the code of mouseDoubleClickEvent in QAbstractItemView.cpp, and I think it is written so that it should always open the editor. I suspect that the way mousePressedEvent() is written means that the double click event isn't generated if the selection change is driven from there (I don't think it should be driven from there - rather it should be driven from a mouseClickedEvent()) which isn't present. I do see code in mousPressedEvent() that is intended to open the editor, but don't quite "get" why that wasn't invoked.
David
-
Did you keep any custom code / event filter after changing to use the selection model ?
-
Then please share a minimal compilable example that shows this behaviour.