Qt World Summit: Register Today!

Qtablewidgetitem and qlistwidgetitem

  • hello i have an item in a qtablewidget, this item is also present in a qlistwidget, how i can get the index of the item in the listwidget, if i heve the tablewidgetitem?
    @QTableWidgetItem *item = new QTableWidgetItem;
    item = ui->tableWidget->item(i,5);

  • May be a call to setCurrentItem and then currentRow should return the item number/index? Of course this means that you know how to convert you tablewidgetitem into a listwidgetitem.
    However I guess your items should be indexed by a complete model when you have more widgets operating on them.

  • i have write this but i get the error:
    usr/include/qt4/QtGui/qlistwidget.h:287: error: ‘QModelIndex QListWidget::indexFromItem(QListWidgetItem*) const’ is protected
    ../packing_NSW/widget.cpp:104: error: within this context

    @ QModelIndex indice;
    QString da_tradurre;
    QListWidgetItem *item_lista = new QListWidgetItem;
    da_tradurre = ui->tableWidget->item(i,5)->text();
    indice = ui->listWidget->indexFromItem(item_lista);

  • Uhm, maybe a cycle can do this:

    @for( int i = 0; i < ui->listWidget->count; i++)
    if( ui->listWidget->item( i ) == your_item )
    index = i; break;

    Nothing smarter come into my mind (except having a separate model).

Log in to reply