Re: [Interest] Revert the selection in a QTreeView
Glenn Ramsey schreef op 14-1-2015 om 00:23: On 14/01/15 11:50, Nurmi J-P wrote: On 13 Jan 2015, at 22:45, Glenn Ramsey g...@componic.co.nz wrote: Hi, In a QTreeView how can I revert the selection? The behaviour I want is that when the user selects an item, then based on some other state, it will either accept the selection or message the user and revert to the previous selection. Have you considered simply disabling such items? Then there's no need to revert anything or show annoying error messages. :) Yes, that might be the right solution. On the other hand, I'm not the interface designer. Consider hiring one. Or at least stick to some basic design principles like the principle of least suprise: you don't want to leave your users guessing what will happen if they do something. They need confidence. One time just selecting an item working, and the next time throwing an error dialog in their face isn't exactly predictable, confidence-building behavior, so best avoid doing that. André ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Revert the selection in a QTreeView
Glenn wrote: Sent: Wednesday, 14 January 2015 8:45 AM Hi, In a QTreeView how can I revert the selection? The behaviour I want is that when the user selects an item, then based on some other state, it will either accept the selection or message the user and revert to the previous selection. The currentChanged method gives me the QModelIndex of the previous selection so I can use treeview.setCurrentIndex to set it to the previous index, but this causes recursion. I guess I could use a flag to prevent the recursion, but I'm wondering if there is a better way to get the same behaviour. Hi Glenn, Don't worry - you'll probably end up with several of these 'prevent recursion' flags for your slots! Note: in Qt 4 there is a bug where calling setCurrentItem in the currentIitemChanged slot after a mouse click may cause all of the items in between to be selected - at least in does in QListView! The solution was to save the previous item, and use QTimer.singleShot( 0, ... ) to a slot that does setCurrentItem on the saved value. Unfortunately, the Qt API doesn't have an interface that allows you to trap the change in selection regardless of the cause. I have recently tried overriding keyboardSearch, moveCursor and mousePressEvent to force the validation before the selection is changed. A similar problem occurs when you need to validate a page in a tab widget before the tab changes. Good Luck! ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Revert the selection in a QTreeView
On 13 Jan 2015, at 22:45, Glenn Ramsey g...@componic.co.nz wrote: Hi, In a QTreeView how can I revert the selection? The behaviour I want is that when the user selects an item, then based on some other state, it will either accept the selection or message the user and revert to the previous selection. Have you considered simply disabling such items? Then there's no need to revert anything or show annoying error messages. :) -- J-P Nurmi ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
[Interest] Revert the selection in a QTreeView
Hi, In a QTreeView how can I revert the selection? The behaviour I want is that when the user selects an item, then based on some other state, it will either accept the selection or message the user and revert to the previous selection. The currentChanged method gives me the QModelIndex of the previous selection so I can use treeview.setCurrentIndex to set it to the previous index, but this causes recursion. I guess I could use a flag to prevent the recursion, but I'm wondering if there is a better way to get the same behaviour. Glenn ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] Revert the selection in a QTreeView
On 14/01/15 11:50, Nurmi J-P wrote: On 13 Jan 2015, at 22:45, Glenn Ramsey g...@componic.co.nz wrote: Hi, In a QTreeView how can I revert the selection? The behaviour I want is that when the user selects an item, then based on some other state, it will either accept the selection or message the user and revert to the previous selection. Have you considered simply disabling such items? Then there's no need to revert anything or show annoying error messages. :) Yes, that might be the right solution. On the other hand, I'm not the interface designer. ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest