Results 1 to 5 of 5

Thread: QAbstactItemView selection after moving rows

  1. #1
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QAbstactItemView selection after moving rows

    I have a a model that is used to represent a media player's playlist. As part of this I need to be able to move items in the model (so that a user can re-order a playlist). In my model I call beginMoveRows()/endMoveRows() - and the selection apeears to update on screen (the moved rows keep their selected background). But if the user then shift-clicks elsewhere, the start of the selection appears to be where the original selection was. e.g.:


    Moving tracks up:
    1. 10 tracks in play list, numbered 1 to 10
    2. Select 8 and 9
    3. Move to under track 3, so we now have 1, 2, 3, 8, 9, 4, 5, 6, 7, 10 (tracks 8 and 9 are still selected)
    4. Shift select track 10
    5. Tracks 8, 6, 7, and 10 are selected - but selection should be 8, 9, 4, 5, 6, 7, 10


    Moving tracks down:
    1. 10 tracks in play list, numbered 1 to 10
    2. Select 2 and 3
    3. Move to under track 8, so we now have 1, 4, 5, 6, 7, 8, 2, 3, 9, 10 (tracks 2 and 3 are still selected)
    4. Shift select track 4
    5. Only tracks 4 and 2 are selected - but selection should be 4, 5, 6, 7, 8, 2, 3


    Reading the QAbstractItemView docs, it states
    If the user presses the Shift key while clicking on an item, all items between the current item and the clicked item are selected...
    So it appears as if the current item is not being updated. I tried to connect to the rowsMoved() signal, and in the slot I checked both the view's, and selection's, current index - both appeared to be fine.

    I have some code that attempts to save, and restore, the current index between updates - but this seems a bit too hacky to me. If possible I'dlike to remove this code, and do it properly!

    What am I missing?

    (The code is part of 'Cantata', which if you are interested you can download from http://kde-apps.org/content/show.php...content=147733)

  2. #2
    Join Date
    Apr 2012
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QAbstactItemView selection after moving rows

    try to change selection mode.

  3. #3
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QAbstactItemView selection after moving rows

    How does that help? That's completly bypassing the issue.

    Looks like this maybe a Qt bug though - as Amarok seems to suffer from the same issue.

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QAbstactItemView selection after moving rows

    Yes, there's a reported bug in Qt as QAbstractItemViewPrivate:ressedPosition is not updated after the drag and drop is performed (and in few other cases like using clearSelection()).
    This results in all selection being done based on wrong mouse position.

    You can fairly easily walk around the bug like that:
    Qt Code:
    1. ...
    2. connect( this->list->model(), SIGNAL( layoutChanged() ), this, SLOT( correctSelection() ) );
    3. ...
    4.  
    5. void MainWindow::correctSelection( void )
    6. {
    7. QItemSelection s = this->list->selectionModel()->selection();
    8. this->list->setCurrentIndex( this->list->currentIndex() );
    9. this->list->selectionModel()->select( s, QItemSelectionModel::SelectCurrent );
    10. }
    To copy to clipboard, switch view to plain text mode 
    I don't think it can be done any better without altering qt source code.
    Last edited by Spitfire; 9th April 2012 at 12:39.

  5. The following user says thank you to Spitfire for this useful post:

    craig_d (16th April 2012)

  6. #5
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QAbstactItemView selection after moving rows

    Works great! Thanks!

Similar Threads

  1. Replies: 2
    Last Post: 12th May 2010, 15:27
  2. Replies: 4
    Last Post: 26th October 2009, 23:25
  3. Replies: 0
    Last Post: 18th September 2009, 15:10
  4. Switching/moving rows in a model
    By gri in forum Qt Programming
    Replies: 4
    Last Post: 17th December 2008, 12:21
  5. QGraphicsView: Moving multiple selection
    By marcel in forum Qt Programming
    Replies: 1
    Last Post: 23rd April 2007, 20:59

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.