April 26, 2011

rudag rudag
Lab Rat
5 posts

data of QTreeView rows


I made a QTreeView with a QStandardItemModel to show some data from a MySQL query as a list and it’s working fine. Now I need to get the ‘double-click’ signal from the QTreeView rows, and fill 3 QLineEdit with the data from the row clicked. How do I get the data from the ‘double-clicked’ row?

1 reply

April 27, 2011

Volker Volker
Ant Farmer
5331 posts

You connect a slot to signal doubleClicked() [doc.qt.nokia.com]. The model index contains parent, row and column of the model index clicked. In your slot, you can get the current values via

  1. int row = index.row();
  2. QModelIndex parent = index.parent();
  3. QString str0 = model->data(model->index(row, 0, parent), Qt::EditRole);
  4. QString str1 = model->data(model->index(row, 1, parent), Qt::EditRole);
  5. QString str2 = model->data(model->index(row, 2, parent), Qt::EditRole);

  ‹‹ Is it possible to play a sound and the moment it ends do something?      How to Use QFileSystemModel ››

You must log in to post a reply. Not a member yet? Register here!