I'm learning Qt Quick to write a file manager. Following the answer to my previous question, now I'm trying to navigate around the directory tree by double-clicking a row (corresponding to a folder) in TableView
, that is, the view should change to the content inside the folder that I just double-clicked.
Conceptually, I'll need to tell onDoubleClicked
to change the folder
property of FolderListModel
, right? But it's not clear to me how to get the model element corresponding to the clicked row? A hard-coded example would be:
TableView {
onDoubleClicked: {
folderModel2.folder = "file:///bin";
}
}
But I want to assign to the folder
property the role fileURL
of the model element corresponding to the row I double-clicked. By the way I'm not planing to explicitly display fileURL
in the TableView
, so I'll have to get the model element itself, not just the view.
Again the starting code is here. Thank you!
It felt like a daunting thing for me, walking in the dark, but after I wrote the question up, it became clearer what exactly to look up. So far a working solution:
TableView {
onDoubleClicked: {
var cur_idx = tableView1.currentRow;
if ( folderModel2.isFolder(cur_idx) ) {
folderModel2.folder = folderModel2.get(cur_idx, "fileURL");
}
}
}
Please let me know if there are better solutions, or if my current code has malpractices in term of QML. Thanks for reading.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments