Different context menu for Items and QTreeView "background"..
-
wrote on 27 Jan 2024, 10:32 last edited by tb24dev
Hello there! o)
I've been reading here and everywhere else for some days now, my eyes already hurt from all the "Q"s in those class names o), but I cannot find any decent advice on how to approach the following:
I'm evaluating whether PySide6 and the QTreeView allows the illustrated behaviour (using customization of course). Priority is on point 1), being able to detect various mouse button clicks (single, double, right vs. left) next to the items text (into the light green area) and to interpret it as targeting the actual container of all the items or the tree view itself. The dark green area should be no problem to handle as container and "not the item", since nothing in those columns will be treated as item. It might be moe difficult to start a drag-select from there though, but that's a future problem.
Point 2) the drag select feature as shown is not available by default in Qt it seems, if I cannot get this to work, this is not a show stopper, but it would hurt a bit! o)
I guess Point 3), the context menu for items (only on their text) and still being able to do 4), the drag'n'drop operations, are less of a problem, if I resolved the other points.
What approach would you choose to tackle the container / tree view context menu? I already read about using item delegators, editors, indexAt(), .isValid(), different ways of hooking into context menu events, but I could not find out how to detect a click outside of the items text area to mimic a click on the tree views "background".
Looking at Windows Explorer, it comes very close to what I try to do.
I am the average dev, from VB-Forms, to HTML to WPF, I've seen some things, I hope I get my head around PyQt as well.
I appreciate any advice, thank you in advance! o)
ps: The first illustration is from my prototype, using QT Designer, layouts, splitters etc. and populating the tree view with columns and file system names (not using this QFilesystemModell, it seemed to be too slow with 3000+ items, at least with loading and showing file icons, which it does by default). So, only after trying and getting my Qt/Python newbie hands dirty a bit, I dared to ask! o)
-
Hi and welcome to devnet,
Some stuff that you should go through:
https://doc.qt.io/qt-6/dnd.html
https://doc.qt.io/qt-6/model-view-programming.html#using-drag-and-drop-with-item-viewsFor the selection, isn't
QAbstractItemView::MultiSelection
what you are looking for ?QMenu is what you are looking for to build your contextual menu.
To do the custom handling of mouse event, you wil have to re-implement the mouse related functions but don't forget to ensure that you are not breaking the original handling as otherwise the drag and drop and selection will also break.
1/2