[Qt-interest] qtreeview - hot do I get current item?
Iuri Fiedoruk
protoman at upperland.net
Sat Feb 13 12:35:59 CET 2010
Hello. I am working in a editor that have a tree with a multi-level model:
model = new QStandardItemModel();
QStandardItem* games = new QStandardItem("GAMES");
n = dataExchanger->freeSlot("data/game", "gme");
for (i=1; i<n; i++) {
dataExchanger->centNumberFormat(i);
sprintf(buffer, "Game %s", dataExchanger->centNumber);
temp_game_item = new QStandardItem(buffer);
temp_game_item->setEditable(FALSE);
games->appendRow(temp_game_item);
sprintf(buffer, "data/game/game_%s/", dataExchanger->centNumber);
n_game = dataExchanger->freeSlot(buffer, "map");
temp_map_item = new QStandardItem("MAPS");
temp_game_item->appendRow(temp_map_item);
for (j=1; j<n_game; j++) {
dataExchanger->centNumberFormat(j);
sprintf(buffer, "%s.map", dataExchanger->centNumber);
temp_sub_map_item = new QStandardItem(buffer);
temp_map_item->appendRow(temp_sub_map_item);
//QObject::connect(ui->pallete, SIGNAL(signalPalleteChanged()),
ui->editArea, SLOT(repaint()));
}
}
model->setHeaderData(0, Qt::Horizontal, "Item List");
ui->mapList->setModel(model);
This creates the following:
Games
- Game 001
- MAPS
- 001.map
- 002.map
- Game 002
(...)
Now what I want, is that when the user clicks or use keyboard to change the
selected item in the tree, I get information about it.
I tryied the click, like this:
void MainWindow::on_mapList_clicked(QModelIndex index)
{
QModelIndex idx = ui->mapList->currentIndex();
if(idx.isValid()) {
QStandardItem* item = model->item(idx.row(), idx.column());
QString text = item->text();
printf("DEBUG.MainWindow::on_mapList_clicked - item clicked, row is: %d,
column is: %d\n", index.row(), index.column());
//printf("DEBUG - text: %s\n", text);
}
}
But item is always empty.
Can you please help me to find a way to just get the text/data from the
current selected item in the tree when it is changed?
Thanks in advance.
--
Iuri Fiedoruk, Developer Engineer.
http://www.greenneko.com - Soluções em Web & Design - Porto Alegre, RS,
Brazil.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100213/851b2bfe/attachment.html
More information about the Qt-interest-old
mailing list