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. QListWidget reorder with Drag and Drop

QListWidget reorder with Drag and Drop

Scheduled Pinned Locked Moved General and Desktop
24 Posts 7 Posters 35.7k 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.
  • S Offline
    S Offline
    szh1
    wrote on last edited by
    #5

    Then, when I try to drag it, it just selects a different row.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #6

      This does the job:

      @
      setDragDropMode(QAbstractItemView::InternalMove);
      @

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      2
      • T Offline
        T Offline
        t3chNo
        wrote on last edited by
        #7

        Set dragEnabled to true.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          szh1
          wrote on last edited by
          #8

          Neither of those are working! :(
          Am I the only one with this problem?

          1 Reply Last reply
          0
          • T Offline
            T Offline
            t3chNo
            wrote on last edited by
            #9

            Which platform are you working on? Is your qt compiled with QT_NO_DRAGANDDROP defined?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              szh1
              wrote on last edited by
              #10

              I am using Windows 7 with the Qt SDK downloaded from qt.nokia.com/downloads. I did not build it myself.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #11

                This works for me:

                @
                #include <QApplication>
                #include <QListWidget>

                int main(int argc, char **argv)
                {
                QApplication a(argc, argv);

                QListWidget lw;
                for(int i = 1; i < 10; ++i)
                    lw.addItem(new QListWidgetItem(QString("Item %1").arg(i)));
                lw.setDragDropMode(QAbstractItemView::InternalMove);
                
                lw.show();
                
                a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
                a.exec&#40;&#41;;
                

                }
                @

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  szh1
                  wrote on last edited by
                  #12

                  Strange. It works for me, too. I wonder why my other application doesn't then.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #13

                    Do you use a user interface made with Qt Designer and did you change some of the drag/drop settings there?

                    http://www.catb.org/~esr/faqs/smart-questions.html

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

                      Do you use QListWidget or QListWidget inherited widget? If you inherit from listWidget and use mouse or drag events and didn't pass event to QListWidget, drag and drop will not work.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        szh1
                        wrote on last edited by
                        #15

                        I made it with Qt Designer and I changed the drag and drop properties a lot, but now I changed them back to just dragDropMode = internalMove and put the others back to default. The selection mode is ExtendedSelection, but I tried the default, too.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          goetz
                          wrote on last edited by
                          #16

                          That should work. I tried this with designer and could move the items in the preview mode (Ctrl-R/Cmd-R). That should work in the real code too, if you do not change other drag/drop settings there too.

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            szh1
                            wrote on last edited by
                            #17

                            Even stranger news:

                            I created a new project, copied and pasted all of the code / widgets, and now its working!

                            Any ideas why this happened and how to prevent it in the future?

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              goetz
                              wrote on last edited by
                              #18

                              Sorry, I do not have any clue what's happening there. Maybe some alien code from outer space? :-)

                              http://www.catb.org/~esr/faqs/smart-questions.html

                              1 Reply Last reply
                              0
                              • T Offline
                                T Offline
                                t3chNo
                                wrote on last edited by
                                #19

                                Here is my scenario: You use visual studio. Your code had little error. Complier didn't compile code and ran old executable.

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  szh1
                                  wrote on last edited by
                                  #20

                                  Actually, I use Qt Creator.

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    samkpo
                                    wrote on last edited by
                                    #21

                                    this helped me a lot! thanks

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      moritzge
                                      wrote on last edited by
                                      #22

                                      helped me too, thanks!

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        ajpieri
                                        wrote on last edited by
                                        #23

                                        Worked for me!

                                        1 Reply Last reply
                                        0
                                        • sonichyS Offline
                                          sonichyS Offline
                                          sonichy
                                          wrote on last edited by
                                          #24

                                          The viewMode should be ListMode(default) but not IconMode, even items have icons.

                                          https://github.com/sonichy

                                          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