Results 1 to 5 of 5

Thread: How can i search selected lines one by one in a QTreeView and get their text

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2007
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can i search selected lines one by one in a QTreeView and get their text

    Hello jpn

    I saw it but i can't understand how to implement it in my code
    here is an example code:

    Qt Code:
    1. Models *model;
    2. QTreeView *usersTree;
    3. usersTree->setModel(model->usersModel);//usersModel returns a QStandardItemModel
    To copy to clipboard, switch view to plain text mode 
    ok i got the users displayed in the tree.

    assume there is a slot btnClicked when i push a button,and inside this slot i have to implement the searching of the selected rows one by one from usersTree,and get their data.

    Can someone give me 3-4-5 lines,having in mind the example code, of how to do that?

    Thank you

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How can i search selected lines one by one in a QTreeView and get their text

    Qt Code:
    1. QModelIndexList indexes = usersTree->selectionModel()->selectedIndexes();
    2. foreach (QModelIndex index, indexes)
    3. {
    4. qDebug() << index.data(Qt::DisplayRole).toString();
    5. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    mekos (25th May 2008)

  4. #3
    Join Date
    Dec 2007
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can i search selected lines one by one in a QTreeView and get their text

    Thanks jpn
    that worked
    take care

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
  •  
Qt is a trademark of The Qt Company.