View Full Version : How can i search selected lines one by one in a QTreeView and get their text
mekos
24th May 2008, 20:09
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
See QAbstractItemView::selectionModel().
mekos
25th May 2008, 18:14
Hello jpn
I saw it but i can't understand how to implement it in my code
here is an example code:
Models *model;
QTreeView *usersTree;
usersTree->setModel(model->usersModel);//usersModel returns a QStandardItemModel
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
QModelIndexList indexes = usersTree->selectionModel()->selectedIndexes();
foreach (QModelIndex index, indexes)
{
qDebug() << index.data(Qt::DisplayRole).toString();
}
mekos
25th May 2008, 20:01
Thanks jpn
that worked ;)
take care
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.