Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qtablewidgetitem and qlistwidgetitem
Qt 6.11 is out! See what's new in the release blog

Qtablewidgetitem and qlistwidgetitem

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luca72
    wrote on last edited by
    #1

    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);
    ?????
    @

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luca72
        wrote on last edited by
        #3

        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();
        item_lista->setText(da_tradurre);
        indice = ui->listWidget->indexFromItem(item_lista);
        @

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fluca1978
          wrote on last edited by
          #4

          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).

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved