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. [SOLVED]Problem while using 'itemFromIndex'.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Problem while using 'itemFromIndex'.

Scheduled Pinned Locked Moved General and Desktop
qlistwidget
4 Posts 2 Posters 1.5k Views 2 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.
  • ealioneE Offline
    ealioneE Offline
    ealione
    wrote on last edited by ealione
    #1

    I have a listWidget in my form and I decided using it's
    on_listView_clicked(const QModelIndex &index)
    signal.

    In the slot implementation I want to get the item clicked each time so since I have the item index I thought about using
    QListWidgetItem * curItm = ui->listView->itemFromIndex(index);

    But I get the error:
    'itemFromIndex' is a protected member of 'QListWidget'

    How can I use this particular function?

    1 Reply Last reply
    0
    • ealioneE Offline
      ealioneE Offline
      ealione
      wrote on last edited by ealione
      #2

      Since this is a protected method (I do not know why) then what one could do is subclass QListWidget. If that is not a n option maybe an alternative could be using

      QListWidgetItem* curItm = ui->listView->item(index->row());

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Why not use the currentItemChanged signal ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • ealioneE Offline
          ealioneE Offline
          ealione
          wrote on last edited by
          #4

          Hi SGaist,
          Mainly because I have also put checkboxes next to each item. I still want the function to fire up no matter if the user clicks the checkbox or the item.
          That is why I think what I suggest (only in this case) is a better idea.

          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