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. Change order of rows in a QTableWidet by drag & drop
Qt 6.11 is out! See what's new in the release blog

Change order of rows in a QTableWidet by drag & drop

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 3 Posters 13.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.
  • D Offline
    D Offline
    Daniel T
    wrote on last edited by
    #9

    I already understand this, but you not answer my answer.
    May be i am not clear ?
    I sent you a website in which already somebody ask this (for a previous Qt version) and receive a answer based on PyQt, but i dont understand well PyQt :
    http://stackoverflow.com/questions/26227885/drag-and-drop-rows-within-qtablewidget/26311179#26311179
    Use "setSectionsMovable" with or without D'n'D stuff, dont work.
    Thanks for you pacience.
    Daniel

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

      Before digging too deep into the D'n'D part
      Does:

      int main(int argc, char *argv[]) 
      {
          QApplication app(argc, argv);
          QTableWidget tw;
          tw.setRowCount(3);
          tw.setColumnCount(3);
      
          for (int i = 0 ; i < tw.rowCount() ; ++i) {
              for (int j = 0 ; j < tw.colorCount() ; ++j) {
                  QTableWidgetItem *item = new QTableWidgetItem(QString("%1 %2").arg(i).arg(j));
                  tw.setItem(i, j, item);
              }
          }
      
          tw.verticalHeader()->setSectionsMovable(true);
          tw.show();
          return app.exec();
      }
      

      do what you want ?
      Note that when setting setSectionsMovable, you have to use the section "button" to move a row.

      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
      • D Offline
        D Offline
        Daniel T
        wrote on last edited by Daniel T
        #11

        Thanks.
        I already compiled this code i tryed it.
        If i drag from (1,1) (which contains "0 0") and drag to (3,1), it simply select (1,1),(2,1) and (3,1)
        I show you this result :
        image
        Sorry i dont now how to "incrust" a image here in this chat, so i give a link.
        What i want to have as a result after dragging from "0 0" to "2 0" is :
        "1 0" "1 1" "1 2"
        "2 0" "2 1" "2 2"
        "0 0" "0 1" "0 2"
        So its like "insert".
        Thanks any more help. Daniel

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

          Using setSectionsMovable, you don't select anything. Just put your mouse on the section number, press and move the section (just like you would do with e.g. Excel or Numbers)

          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
          • D Offline
            D Offline
            Daniel T
            wrote on last edited by
            #13

            Of course this is what do :
            Make a click over "0,0". This will select "0,0". I drag my mouse until i am over "2 0", release, and i already show you which result i get.
            No reorder, no insertion , only selection from "0 0" to "2 0"
            Daniel

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Daniel T
              wrote on last edited by
              #14

              Hi.
              I found a way.
              However dragging a cell not work, its work if a drag a vertical header.
              Of course it would good if i can drag cells of column 0, but i am already satisfied for this moment.
              Thanks. Daniel

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

                You're doing the opposite of what I ask you to try. By the way, if you want to move the columns you need to set the section movable property on the horizontal header (I know, this one is a bit confusing)

                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
                • D Offline
                  D Offline
                  Daniel T
                  wrote on last edited by
                  #16

                  What i move are items of the header which is at left. I called it QVertcalHeader.
                  I am wrong ? Anyway, setting this QVertcalHeader to movable, permit me to move rows (moveing items on this header)
                  I also search for get a answer, which one is a QVerticalHeader, but for now this is for me more raisonable.
                  I only know to which say a "row header" at : https://documentation.devexpress.com/#WindowsForms/CustomDocument387
                  greatings, Daniel

                  1 Reply Last reply
                  0
                  • yeckelY Offline
                    yeckelY Offline
                    yeckel
                    wrote on last edited by
                    #17

                    Hi Daniel, there was a bugQTBUG-48408 is it the same problem? Should be solved in Qt5.6.

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

                      @yeckel nop, that's not the same thing. That bug's about the selection model + sorting. Here the subject is moving a row up/down.

                      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

                      • Login

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