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. QList Widget Getting text from Selected Index
QtWS25 Last Chance

QList Widget Getting text from Selected Index

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 8.7k Views
  • 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.
  • V Offline
    V Offline
    vezprog
    wrote on last edited by
    #1

    I am just starting to learn how to use QList Widgets. I am able to add items to my ListWidget, as well as select which one I want. What I want to do is when I click a button, I want to get the string that is selected (from the highlighted index within the list widget) and store it into a variable. Is this possible?

    Thanks in advance.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      Perhaps you want to use "currentItem()":http://doc.qt.nokia.com/4.7-snapshot/qlistwidget.html#currentItem on your QListWidget, and then "text()":http://doc.qt.nokia.com/4.7-snapshot/qlistwidgetitem.html#text on the returned QListWidgetItem.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        amban
        wrote on last edited by
        #3

        Hi,
        I have done the same thing this week. Here's what i did -
        @
        for (int list=0; list < listmodel->rowCount(); list++)
        {
        QStandardItem *newitem= listmodel->item(list);
        if(newitem->checkState() == 2) //For all checked items
        {
        // store it into your variable using newitem->text()
        }
        }
        @
        There are several ways of doing it, this is one.
        Hope this helps.

        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