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 add selected items from table widget into a queue?
Forum Updated to NodeBB v4.3 + New Features

How to add selected items from table widget into a queue?

Scheduled Pinned Locked Moved Unsolved General and Desktop
table widgetqt5
11 Posts 4 Posters 1.4k 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.
  • C Offline
    C Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 18 Mar 2021, 06:11 last edited by
    #2

    @suslucoder said in How to add selected items from table widget into a queue?:

    If i understand how can i get selected items, it will be easy to add them on a queue
    ui->tableWidget->selectedItems();

    You can get the selected items with this function. So use it.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    D 1 Reply Last reply 18 Mar 2021, 06:18
    1
    • D deleted286
      18 Mar 2021, 06:10

      Hi everyone. I have a table widget. Im loading some data to my widget from a txt file.
      I want to select some datas on my table, how can i get the exact values which i selected from table?

      I have this one, but it returns a list of pointers.
      I want to get exact values which is on my table.
      If i understand how can i get selected items, it will be easy to add them on a queue

      ui->tableWidget->selectedItems();
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 18 Mar 2021, 06:12 last edited by
      #3

      @suslucoder said in How to add selected items from table widget into a queue?:

      I want to get exact values which is on my table.

      And what is the problem?
      You can store pointers in a queue, or simply de-reference the pointers when adding them to the queue (C++ basics: *pointer).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 18 Mar 2021, 06:17 last edited by
        #4

        Hi

        how can i get the exact values which i selected from table?

        You mean its texts ?

        QList<QTableWidgetItem*> MySelList =  m_ui->tableWidget->selectedItems();
          for (QTableWidgetItem* item : MySelList) {
            QString TheText = item->text();
           // do stuff with text.
          }
        
        
        D 1 Reply Last reply 18 Mar 2021, 06:20
        1
        • C Christian Ehrlicher
          18 Mar 2021, 06:11

          @suslucoder said in How to add selected items from table widget into a queue?:

          If i understand how can i get selected items, it will be easy to add them on a queue
          ui->tableWidget->selectedItems();

          You can get the selected items with this function. So use it.

          D Offline
          D Offline
          deleted286
          wrote on 18 Mar 2021, 06:18 last edited by
          #5

          @Christian-Ehrlicher

          I want to achieve somethings like this

          ui->tableWidget->item(row,2)->text().toDouble();
          

          Im using the 2th column's value, so when i select more tha one item, it should return me to last columns value

          J 1 Reply Last reply 18 Mar 2021, 06:20
          0
          • D deleted286
            18 Mar 2021, 06:18

            @Christian-Ehrlicher

            I want to achieve somethings like this

            ui->tableWidget->item(row,2)->text().toDouble();
            

            Im using the 2th column's value, so when i select more tha one item, it should return me to last columns value

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 18 Mar 2021, 06:20 last edited by
            #6

            @suslucoder said in How to add selected items from table widget into a queue?:

            so when i select more tha one item

            I don't understand: you want to get selected items, what ever user selected, right? What should happen if user does not select anything in column 2? Can you please explain better what you're trying to achieve?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            D 1 Reply Last reply 18 Mar 2021, 06:22
            1
            • M mrjj
              18 Mar 2021, 06:17

              Hi

              how can i get the exact values which i selected from table?

              You mean its texts ?

              QList<QTableWidgetItem*> MySelList =  m_ui->tableWidget->selectedItems();
                for (QTableWidgetItem* item : MySelList) {
                  QString TheText = item->text();
                 // do stuff with text.
                }
              
              
              D Offline
              D Offline
              deleted286
              wrote on 18 Mar 2021, 06:20 last edited by
              #7

              @mrjj
              Yes i mean this.
              Thank you. Is there any way to specify the column in that code script?

              1 Reply Last reply
              0
              • J jsulm
                18 Mar 2021, 06:20

                @suslucoder said in How to add selected items from table widget into a queue?:

                so when i select more tha one item

                I don't understand: you want to get selected items, what ever user selected, right? What should happen if user does not select anything in column 2? Can you please explain better what you're trying to achieve?

                D Offline
                D Offline
                deleted286
                wrote on 18 Mar 2021, 06:22 last edited by
                #8

                @jsulm they cant. Because the other columns have string. Only the second column has double values, which they are need

                J 2 Replies Last reply 18 Mar 2021, 06:24
                0
                • D deleted286
                  18 Mar 2021, 06:22

                  @jsulm they cant. Because the other columns have string. Only the second column has double values, which they are need

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 18 Mar 2021, 06:24 last edited by
                  #9

                  @suslucoder Do you mean user can only select items in column 2? If it is like this then there is no problem at all, simply use code @mrjj provided. All maybe I still don't understand you.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  D 1 Reply Last reply 18 Mar 2021, 06:28
                  1
                  • D deleted286
                    18 Mar 2021, 06:22

                    @jsulm they cant. Because the other columns have string. Only the second column has double values, which they are need

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 18 Mar 2021, 06:25 last edited by
                    #10

                    @suslucoder Actually, you can check from which column an item is coming: https://doc.qt.io/qt-5/qtablewidgetitem.html#column
                    So, use it and only add items from column 2...

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    3
                    • J jsulm
                      18 Mar 2021, 06:24

                      @suslucoder Do you mean user can only select items in column 2? If it is like this then there is no problem at all, simply use code @mrjj provided. All maybe I still don't understand you.

                      D Offline
                      D Offline
                      deleted286
                      wrote on 18 Mar 2021, 06:28 last edited by
                      #11

                      @jsulm thank you.
                      I changed the selection behavior and it works.

                      1 Reply Last reply
                      0

                      11/11

                      18 Mar 2021, 06:28

                      • Login

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