Results 1 to 2 of 2

Thread: QItemSelection::select on a Tree model

  1. #1
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QItemSelection::select on a Tree model

    Hi there,

    I'm trying to programmatically select a number of rows in a QTreeView showing the contents of a custom QStandardItemModel.
    Qt Code:
    1. QItemSelectionModel* selectionModel = myTreeView->selectionModel();
    2. QItemSelection selectedItems;
    3.  
    4. selectedItems.select(topIndex, bottomIndex);
    5. selectionModel->select(selectedItems, QItemSelectionModel::ClearAndSelect);
    To copy to clipboard, switch view to plain text mode 

    When the topIndex (May 01) and bottomIndex (May 02) rows have the same parent, it works well.
    + May
    |-- 01 // selected
    |-- 02 // selected
    However, if the bottomIndex (May 02) doesn't have the same parent as the topIndex (April 30), no items are selected:
    + April
    |-- ...
    |-- 30
    + May
    |-- 01
    |-- 02
    Is this a limitation of QItemSelection::select method? Or am I misusing it?
    I was wondering if this should be done manually, by selecting individual ranges in each branch and merging them after.

    Thank you for your answer!

    Best,
    j

  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: QItemSelection::select on a Tree model

    If you want to select items with different parents, you have to merge separate selections. Even though your view shows May 1 after April 30, in the model there is no order relation between those two elements thus you cannot define a continous "range" covering both of them.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    jeeie (8th April 2014)

Similar Threads

  1. SQL Tree Model Help
    By MTK358 in forum Newbie
    Replies: 9
    Last Post: 22nd June 2015, 15:02
  2. Replies: 1
    Last Post: 29th August 2013, 05:41
  3. QTableView and QItemSelection model bug.
    By hickscorp in forum Qt Programming
    Replies: 0
    Last Post: 17th November 2011, 17:49
  4. Editable Tree Model
    By kloffy in forum Qt Programming
    Replies: 5
    Last Post: 10th October 2007, 15:49
  5. using the example of simple tree model
    By krishna.bv in forum Qt Programming
    Replies: 1
    Last Post: 22nd December 2006, 12:28

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.