Frage

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);
}
War es hilfreich?

Lösung

The signal emitted by the QListView has a QModelIndex object as a parameter. Edit your slot that it matches the signature of the signal: void MainWindow::hItem(QModelIndex idx).

With your QModelIndex object you can retrieve the clicked row by using column() or row(). See here: http://harmattan-dev.nokia.com/docs/library/html/qt4/qmodelindex.html

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top