Qt 5.9.2 QTreeView - Drag & Drop Broken ?



  • 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



  • 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.



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



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



  • 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.



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



  • 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.



  • 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 ;/


  • Qt Champions 2016

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



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


  • Qt Champions 2016

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



  • @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 :- )


  • Qt Champions 2016

    @Dariusz
    Super. good work.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.