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.6k 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 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
    1
    • D deleted286

      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();
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on 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
        1
        • Christian EhrlicherC Christian Ehrlicher

          @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 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

          jsulmJ 1 Reply Last reply
          0
          • D deleted286

            @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

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on 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
            1
            • mrjjM mrjj

              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 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
              • jsulmJ jsulm

                @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 last edited by
                #8

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

                jsulmJ 2 Replies Last reply
                0
                • D deleted286

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

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 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
                  1
                  • D deleted286

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

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 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
                    • jsulmJ jsulm

                      @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 last edited by
                      #11

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

                      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