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. Qt 5.9.2 QTreeView - Drag & Drop Broken ?
Qt 6.11 is out! See what's new in the release blog

Qt 5.9.2 QTreeView - Drag & Drop Broken ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 5.0k Views 3 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
    Dariusz
    wrote on last edited by Dariusz
    #1

    Been going nuts for past 4 hours as I had a complex treeView system and took me a while to just do a basic test and realize that the QT is apparently broken?

    The gif showing the workflow to reproduce the issue > https://imgur.com/a/pRKTh

    I cant Upload my files so here is the content...

    main.cpp

    #include <iostream>
    #include "mainwindow.h"
    #include <QApplication>
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        mainWindow widget;
        widget.show();
        return a.exec();
    }
    

    mainWindow.h

    #ifndef QT_03_TREEVIEW_DRAGDROP_HIERISSUE_MAINWINDOW_H
    #define QT_03_TREEVIEW_DRAGDROP_HIERISSUE_MAINWINDOW_H
    #pragma once
    #include <QMainWindow.h>
    #include "QVBoxLayout"
    #include "QTreeView"
    #include "QLabel"
    #include "QPushButton"
    #include <QHeaderView>
    #include <QStandardItemModel>
    using namespace std;
    class mainWindow : public QMainWindow {
    public:
        mainWindow(QWidget *parent = 0);
        ~mainWindow();
    private:
        QVBoxLayout *layout;
        QTreeView *tree;
        QStandardItemModel *iModel;
        void addLayer(int a);
    };
    #endif //QT_03_TREEVIEW_DRAGDROP_HIERISSUE_MAINWINDOW_H
    

    mainWindow.cpp

    #include "mainWindow.h"
    mainWindow::mainWindow(QWidget *parent) : QMainWindow(parent) {
        QWidget *w = new QWidget;
        setCentralWidget(w);
        setGeometry(500, 500, 1000, 1000);
        layout = new QVBoxLayout;
        layout->addWidget(new QLabel("TestTree"));
        centralWidget()->setLayout(layout);
        QPushButton *btn_layer = new QPushButton("Layer");
        connect(btn_layer, &QPushButton::clicked, this, &mainWindow::addLayer);
        layout->addWidget(btn_layer);
        iModel = new QStandardItemModel();
        tree = new QTreeView(this);
        tree->setModel(iModel);
        tree->setSelectionMode(QAbstractItemView::ExtendedSelection);
        tree->setAcceptDrops(true);
        tree->setDragEnabled(true);
        tree->setAutoScroll(true);
        tree->setDragDropMode(QAbstractItemView::InternalMove);
        tree->setDropIndicatorShown(true);
        tree->setAlternatingRowColors(true);
        iModel->setHorizontalHeaderLabels({"Name", "xx1", "xx2", "xx3"});
        tree->setSelectionMode(QAbstractItemView::ExtendedSelection);
        layout->addWidget(tree);
    }
    
    void mainWindow::addLayer(int a) {
        QStandardItem *itm = new QStandardItem();
        itm->setText(QString("Hey you Im parent  ") + to_string(a).c_str());
        itm->setCheckable(true);
        itm->isDragEnabled();
        itm->isDropEnabled();
        itm->setCheckState(Qt::Checked);
        QStandardItem *itm2 = new QStandardItem();
        itm2->setCheckable(true);
        itm2->setCheckState(Qt::Unchecked);
        QStandardItem *itm3 = new QStandardItem();
        itm3->setText("xx2");
        QStandardItem *itm4 = new QStandardItem();
        itm4->setText("xx3");
        iModel->appendRow({itm, itm2, itm3, itm4});
    }
    mainWindow::~mainWindow() {
    }
    

    Can any1 confirm the bug & suggest a fix perhaps?

    Specs:
    cLion & QtCreator 4.4.1
    Visual Studio 2015/2017 - community editions
    X64 build - if that make sense
    Win 10x64 Pro

    Regards
    Dariusz

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kenchan
      wrote on last edited by
      #2

      Hi @Dariusz.

      So what OS and toolchain are you using?
      I tried your code on macOS 10.13.1 High Sierra clang and xCode Version 9.1 (9B55). I did not see the issue you describe in the video.

      D 1 Reply Last reply
      0
      • K kenchan

        Hi @Dariusz.

        So what OS and toolchain are you using?
        I tried your code on macOS 10.13.1 High Sierra clang and xCode Version 9.1 (9B55). I did not see the issue you describe in the video.

        D Offline
        D Offline
        Dariusz
        wrote on last edited by
        #3

        @kenchan said in Qt 5.9.2 QTreeView - Drag & Drop Broken ?:

        Hi @Dariusz.

        So what OS and toolchain are you using?
        I tried your code on macOS 10.13.1 High Sierra clang and xCode Version 9.1 (9B55). I did not see the issue you describe in the video.

        I added details at the bottom of the topic, sorry for not getting it initially.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kenchan
          wrote on last edited by
          #4

          OK, I have a similar windows setup as you so I will try it on that later and let you know how it goes.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kenchan
            wrote on last edited by
            #5

            I built that on my Windows 10x64 Qt 5.9.2 Visual Studio 2015 pro.
            I did not see the issue you describe in the video.

            D 1 Reply Last reply
            1
            • K kenchan

              I built that on my Windows 10x64 Qt 5.9.2 Visual Studio 2015 pro.
              I did not see the issue you describe in the video.

              D Offline
              D Offline
              Dariusz
              wrote on last edited by
              #6

              @kenchan said in Qt 5.9.2 QTreeView - Drag & Drop Broken ?:

              I built that on my Windows 10x64 Qt 5.9.2 Visual Studio 2015 pro.
              I did not see the issue you describe in the video.

              Using the same code? - just 2x checking. This is nuts then ! I have no idea how to even approach something like that o.o. Will try to run the code on my laptop see if he produces the same issue.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kenchan
                wrote on last edited by
                #7

                Yes I copied and pasted the code you posted and tested it on macOS and windows.
                I did not see what you show in the video.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Dariusz
                  wrote on last edited by
                  #8

                  This makes no sense at all. I dug out my laptop/tabled that is mostly facebook used. Spend 1h setting up visual studio qt and clion. Coded up the test from the ground up, drag/drop and I'm getting the same incorrect behavior I described above. What the hell is going on o.o ?! I now have 2 separate pcs that have that issue ;/

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi
                    Win 10, Qt 5.9. visual 2015.
                    I cannot make it break.

                    D 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      Hi
                      Win 10, Qt 5.9. visual 2015.
                      I cannot make it break.

                      D Offline
                      D Offline
                      Dariusz
                      wrote on last edited by
                      #10

                      @mrjj said in Qt 5.9.2 QTreeView - Drag & Drop Broken ?:

                      Hi
                      Win 10, Qt 5.9. visual 2015.
                      I cannot make it break.

                      Thanks for testing it !

                      Are you dragging the 1st item from 1st group and 1st item from a group in 1st group? I mean like on the gif? I noticed if I drag it differently then it works but if I do that exact move then it breaks. I don't know how only I have the issues with 2 different pcs...

                      mrjjM 1 Reply Last reply
                      0
                      • D Dariusz

                        @mrjj said in Qt 5.9.2 QTreeView - Drag & Drop Broken ?:

                        Hi
                        Win 10, Qt 5.9. visual 2015.
                        I cannot make it break.

                        Thanks for testing it !

                        Are you dragging the 1st item from 1st group and 1st item from a group in 1st group? I mean like on the gif? I noticed if I drag it differently then it works but if I do that exact move then it breaks. I don't know how only I have the issues with 2 different pcs...

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @Dariusz
                        Yes I tried following video.
                        Could have missed something but did try multiple times.

                        D 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @Dariusz
                          Yes I tried following video.
                          Could have missed something but did try multiple times.

                          D Offline
                          D Offline
                          Dariusz
                          wrote on last edited by
                          #12

                          @mrjj said in Qt 5.9.2 QTreeView - Drag & Drop Broken ?:

                          @Dariusz
                          Yes I tried following video.
                          Could have missed something but did try multiple times.

                          Black magic. In any case I reported it as bug and they - I think - have reproduced it as its now marked as P2. https://bugreports.qt.io/browse/QTBUG-64445

                          Thanks for ur time folks! Fingers cross QT team will fix it :- )

                          mrjjM 1 Reply Last reply
                          1
                          • D Dariusz

                            @mrjj said in Qt 5.9.2 QTreeView - Drag & Drop Broken ?:

                            @Dariusz
                            Yes I tried following video.
                            Could have missed something but did try multiple times.

                            Black magic. In any case I reported it as bug and they - I think - have reproduced it as its now marked as P2. https://bugreports.qt.io/browse/QTBUG-64445

                            Thanks for ur time folks! Fingers cross QT team will fix it :- )

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @Dariusz
                            Super. good work.

                            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