Get the data / text from the model, to which the item belongs to, like this
void MainWindowContainer
::tree_itemClicked(const QModelIndex & index
) {
QString groupID
= index.
model()->data
(index, Qt
::UserRole).
toString();
QString groupName
= index.
model()->data
(index, Qt
::DataRole).
toString();
//or
QString groupID
= index.
data(Qt
::UserRole).
toString();
QString groupName
= index.
data(Qt
::DataRole).
toString();
}
void MainWindowContainer::tree_itemClicked(const QModelIndex & index)
{
QString groupID = index.model()->data(index, Qt::UserRole).toString();
QString groupName = index.model()->data(index, Qt::DataRole).toString();
//or
QString groupID = index.data(Qt::UserRole).toString();
QString groupName = index.data(Qt::DataRole).toString();
}
To copy to clipboard, switch view to plain text mode
If you want the data from column 0, then create index for column 0 then get the data for it, like this
void MainWindowContainer
::tree_itemClicked(const QModelIndex & index
) {
QString groupID
= index.
model()->data
(index.
model()->index
(index.
row(),
0, index.
parent()), Qt
::UserRole).
toString();
QString groupName
= index.
model()->data
(index.
model()->index
(index.
row(),
0, index.
parent()), Qt
::DataRole).
toString();
//or
QString groupID
= index.
model()->index
(index.
row(),
0, index.
parent()).
data(Qt
::UserRole).
toString();
QString groupName
= index.
model()->index
(index.
row(),
0, index.
parent()).
data(Qt
::DataRole).
toString();
}
void MainWindowContainer::tree_itemClicked(const QModelIndex & index)
{
QString groupID = index.model()->data(index.model()->index(index.row(), 0, index.parent()), Qt::UserRole).toString();
QString groupName = index.model()->data(index.model()->index(index.row(), 0, index.parent()), Qt::DataRole).toString();
//or
QString groupID = index.model()->index(index.row(), 0, index.parent()).data(Qt::UserRole).toString();
QString groupName = index.model()->index(index.row(), 0, index.parent()).data(Qt::DataRole).toString();
}
To copy to clipboard, switch view to plain text mode
Bookmarks