No, setSelection() is fine. What's the problem with it?![]()
J-P Nurmi
Well, I guess my problem is that I do not need to support selection with a rectangle or with the keyboard. I only want items to be selected when a user clicks on them with the mouse. Unfortunately, setSelection() only takes a QRect and a SelectionFlag as parameters. What is your recommendation in this case?
Well, I'd implement the selection like the framework expects you to, with setSelection(). Notice that there are a few built-in properties to adjust the way selection works (namely selection behavior and mode). These properties are properly taken into consideration in various methods of QAbstractItemView which further call setSelection(). So I'd use setSelection() instead of reimplementing the selection from scratch to a certain event handler. You can later restrict the ways of selection if really required, for example with empty event handler reimplementation(s).
J-P Nurmi
Ok, I have the selection behavior and mode flags set the way I want them, but I'm still confused on how to re-implement setSelection() for what I need it to do. Since the method is not passed a QPoint or QModelIndex, I have no way to tell which item the user clicked on. Do you see my dilemma here?![]()
My guess is that "indexAt(rect.center())" is suitable for you.
J-P Nurmi
krudio (6th February 2008)
Bookmarks