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. Actions on selected items from QListWidget when button is clicked
Forum Updated to NodeBB v4.3 + New Features

Actions on selected items from QListWidget when button is clicked

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

    Hello everybody,

    So, I have a QListWidget with some items (item1, item2, item3,...). In the app I want to make that you can select one item, click a button to confirm and then get some result based on the item you selected.
    I know how to get indexes of items like this:

    int index=ui->mylist->currentRow();
    

    but how to do something when a button(showBtn) is clicked?

    sierdzioS 1 Reply Last reply
    0
    • Y YouKnowMe

      Hello everybody,

      So, I have a QListWidget with some items (item1, item2, item3,...). In the app I want to make that you can select one item, click a button to confirm and then get some result based on the item you selected.
      I know how to get indexes of items like this:

      int index=ui->mylist->currentRow();
      

      but how to do something when a button(showBtn) is clicked?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @YouKnowMe said in Actions on selected items from QListWidget when button is clicked:

      Hello everybody,

      So, I have a QListWidget with some items (item1, item2, item3,...). In the app I want to make that you can select one item, click a button to confirm and then get some result based on the item you selected.
      I know how to get indexes of items like this:

      int index=ui->mylist->currentRow();
      

      but how to do something when a button(showBtn) is clicked?

      You need to create a slot and connect your button's clicked() signal to it.

      (Z(:^

      Y 1 Reply Last reply
      0
      • sierdzioS sierdzio

        @YouKnowMe said in Actions on selected items from QListWidget when button is clicked:

        Hello everybody,

        So, I have a QListWidget with some items (item1, item2, item3,...). In the app I want to make that you can select one item, click a button to confirm and then get some result based on the item you selected.
        I know how to get indexes of items like this:

        int index=ui->mylist->currentRow();
        

        but how to do something when a button(showBtn) is clicked?

        You need to create a slot and connect your button's clicked() signal to it.

        Y Offline
        Y Offline
        YouKnowMe
        wrote on last edited by
        #3

        @sierdzio I did that, but how to pass an index of the selected item and do actions specific to that item?

        sierdzioS 1 Reply Last reply
        0
        • Y YouKnowMe

          @sierdzio I did that, but how to pass an index of the selected item and do actions specific to that item?

          sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          @YouKnowMe said in Actions on selected items from QListWidget when button is clicked:

          @sierdzio I did that, but how to pass an index of the selected item and do actions specific to that item?

          const auto &selection = ui->myList->selectionModel()->selectedIndexes();
          // Or
          const auto &selection = ui->myList->selectionModel()->currentIndex();
          

          (Z(:^

          1 Reply Last reply
          2

          • Login

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