Results 1 to 4 of 4

Thread: QAbstractItemView and updating selected items

  1. #1
    Join Date
    May 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default QAbstractItemView and updating selected items

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QAbstractItemView and updating selected items

    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().

  3. #3
    Join Date
    May 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QAbstractItemView and updating selected items

    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().

  4. #4
    Join Date
    May 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QAbstractItemView and updating selected items

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.