Results 1 to 3 of 3

Thread: QTableView problem - selecting multiple items

  1. #1
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    3

    Default QTableView problem - selecting multiple items

    I have set up a QAbstractItemModel for a QTableView.
    Also implemented a selectionChanged signal for selecting multiple rows in QTableView.

    However, when I select more than one items in the QTableView, I found only the last item has been identified by the QModelIndexList (selected.indexes()).

    Anyone has any advice.
    I am grateful for your comment and suggestions.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView problem - selecting multiple items

    What did you do in selectionChanged slot ? Its a virtual slot, and what changes have you done to it ?

    Also have you tried setting the selection mode to multi selection ?

  3. #3
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    3

    Default Re: QTableView problem - selecting multiple items

    Do you mean selectionChanged signal? I made a customised slot to be invoked by the selectionChanged signal.

    Yes, I have set the selection mode of the QTableView as QAbstractItemView::ExtendedSelection.


    Added after 6 minutes:


    For the connection:
    Qt Code:
    1. connect(entityTableView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this,
    2. SLOT(selectionChangedSlot(const QItemSelection &, const QItemSelection &)));
    To copy to clipboard, switch view to plain text mode 

    For the slot:
    Qt Code:
    1. void Scope::selectionChangedSlot(const QItemSelection &selected, const QItemSelection &deselected)
    2. {
    3. int selectedItems = 0;
    4. QModelIndexList items = selected.indexes();
    5. selectedItems = selected.indexes().size();
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    Everytime, the selectedItems is equal to 1 not the number that I have selected.
    Last edited by junhonguk; 18th July 2012 at 15:16.

Similar Threads

  1. Selecting items in a QTreeWidget with the keyboard
    By Berryblue031 in forum Qt Programming
    Replies: 2
    Last Post: 19th June 2013, 11:12
  2. QTableWidget - problem when editing multiple items
    By xportation in forum Qt Programming
    Replies: 3
    Last Post: 21st October 2011, 11:38
  3. Replies: 1
    Last Post: 12th November 2009, 19:05
  4. Replies: 2
    Last Post: 30th July 2009, 11:20
  5. Replies: 1
    Last Post: 7th April 2006, 12:13

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.