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. How to get index of listWidget item found by its "text/value"
Forum Updated to NodeBB v4.3 + New Features

How to get index of listWidget item found by its "text/value"

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 462 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.
  • ademmlerA Offline
    ademmlerA Offline
    ademmler
    wrote on last edited by
    #1

    Hi to all,

    I have a listWidget, where I can drag and reorder a list of colors(red, green, blue ...).
    I would like to get the "index" aka actual positionby searching for the color name.
    I already find the element, but I can't get its index.

    How can I do this?

    Pseudo code:
    for (unsigned int i = 0; i < ColoList.size; i++) {
            qDebug() << "List: " <<ColoList[i].name;
            QList<QListWidgetItem*> items = ui->listWidget->findItems(ColoList[i].name, Qt::MatchExactly);
           index = item[0].????
        }
    

    thx in advance

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #2

      QListWidget::row() or QListWidget::indexFromItem() then access the row().

      BTW: the list of matches can be empty.

      1 Reply Last reply
      3

      • Login

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