Results 1 to 5 of 5

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

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

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

    Hello
    I have a QTreeView which calls the setModel function and gets a QStandardItemModel (e.g usersModel) to get the data inside it.
    Is there any way to search all the lines in the tree one by one to find which are selected,and get the text of that lines,when i click on a PushButton??
    Thanks

  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

    J-P Nurmi

  3. #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

    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

  4. #4
    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

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

    mekos (25th May 2008)

  6. #5
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.