Solved how to prevent QTreeView selection changing
-
hi, all:
How to prevent QTreeView selection changing from one node to another node by dynamic condition? -
Hi,
What would this "dynamic condition" be ?
-
Hi, It's mean control by code. Example, show a message box to the user, user can choice cancel.
-
One possible way would be to connect to the QItemSelectionModel::selectionChanged signal and if cancel is called, re-select the deselected items. However you will likely have to block signals while doing that to avoid having it called again while manipulating the selection in that case.
Can you explain why you want to do that that way exactly ?
-
@SGaist thks for reply.
I've considered this approach, but I think it's not the direct way.
Is there any other way?
We known the window closeEvent can cancel to prevent close window, i want to known if the QTreeView have some event like it?It's just sometimes needed.
-
You don't answer my question: why do you need that ? "It sometimes needed" doesn't provide any context for that.
-
@SGaist thks for reply.
I've already explained that before. -->Example, show a message box to the user, user can choice cancel. ---Is this information enough to answer your questions? :)In the delphi treeview have the OnChanging event, In c#(.net) treeview have the BeforeSelect event, there are very useful for some time.
Generally, it use to check some process is finish, if not, cancel changing.
I think, this event also should exists in the qtreeview.
-
I would rather do it the other way around: if a process has to run, don't allow modifications. If it is a cancellable process then have a button to do so explicitly. That will make the user interface clearer.
For the behaviour you want, you'd have to write a custom QTreeView and reimplement the mouse related methods.
-
@SGaist Ok, I see. Thank you very much!