Tuesday, 6 August 2013

How to get the index or string of the row selected in the QListView?

How to get the index or string of the row selected in the QListView?

Not sure how to display the item or index clicked in the list?
{
...
nrow = 10;
ncol = 1;
/*create QListView */
m_listView = new QListView(this);
m_listView->setGeometry(QRect(QPoint(0,100), QSize(100, 150)));
connect(m_listView, SIGNAL(clicked(QModelIndex)), this, SLOT(hItem()));
QStandardItemModel *model = new QStandardItemModel( nrow, 1, this );
//fill model value
for( int r=0; r<nrow; r++ )
{
QString sstr = "[ " + QString::number(r) + " ]";
QStandardItem *item = new QStandardItem(QString("Idx ") + sstr);
model->setItem(r, 0, item);
}
}
void MainWindow::hItem()
{
m_txt1->setText(item@clicked);
}

No comments:

Post a Comment