PDA

View Full Version : QAbstractItemView and updating selected items



Isaac
13th June 2008, 03:28
I have created my own custom view for the model/view framework that inherits from QAbstractItemView. My view is basically a scatter plot from two columns in the model. Each Item (or pair of items in a row) is represented by a small square in the plot. When an item is selected I change its color in the plot.

My problem is that the selected items are only updated when the mouse cursor moves over a plotted point. From the documentation this appears to be how selections have been designed and it works fine for the tableview because you always move the mouse over cells when you are creating selections. This doesn't work in my case because the selectedItems needs to be updated whenever the rubberband region changes (mouse move event maybe).

Should I add a new call to the setSelection(QRect..) function whenever the mouse moves?

Thanks -Isaac

wysota
13th June 2008, 07:33
What you say here is not correct. Rubberbanding also causes items to refresh. If it doesn't in your case, you probably implemented one of the virtual methods incorrectly - most probably visualRect() or indexAt().

Isaac
13th June 2008, 12:13
visualRect(QModelIndex &i) returns the smallest rectangle that encloses the "dot" used to represent the item with index i in the scatterplot.

indexAt(QPoint &p) returns the index of the item at point p. If there is no item present I return QModelIndex().

Isaac
13th June 2008, 12:23
I followed the pattern in the itemviews/chart example as best as I understood. The rubberband selection works the same in my application as it does in this example - if I drag the rubberband around the outide of the chart without ever touching one of the pieslices(items), they never get selected.