Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.12.4
-
None
-
Expected to be hardware independent. Tested on two different laptops. One running windows and another running ubuntu.
Description
Scenario:
- TreeView (model based).
- The custom model inherits from QStandardItemModel with a custom model. In the model the *mimeData and canDropMimeData functions are overridden.
- It should be possible to drag/drop items in the tree
Observations:
- when and item drag is started SLOWLY such that the item is first dropped onto itself, resulting in a "can-not-drop" cursor, then none of the other nodes will accept the item afterwards.
- Except when the node is dragged out of the window and then back into it, entering the control via one of the nodes that will accept the item. In that case the canDropMimeData function is called on that node and everything works fine.
I suspect that this is similar to QTBUG-44939 although it also occurs when canDropMimeData always returns true.
Tested in both C++ (windows 10) and python (windows 10 / linux).
C++ code:
#include <QApplication> #include <QTreeView> #include <iostream> #include <QMimeData> #include <QHeaderView> #include <QStandardItemModel> class SceneTreeModel : public QStandardItemModel { virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const { std::cout << "canDrop called\n"; return true; } virtual QMimeData *mimeData(const QModelIndexList &indexes) const { QMimeData *mimeData = new QMimeData; mimeData->setText("SomeText"); std::cout << "mimeData provided\n"; return mimeData; } /* as suggested in QTBUG-52044 , does not help virtual QStringList mimeTypes() const { QStringList mts; mts << "x-dragdrop/Item"; return mts; } */ }; int main( int argc, char **argv ) { QApplication app( argc, argv ); QTreeView *tree = new QTreeView(); SceneTreeModel model; QStandardItem *item1 = new QStandardItem( QString("Item1")); model.invisibleRootItem()->appendRow(item1); QStandardItem *item2 = new QStandardItem( QString("Item2")); item1->appendRow(item2); QStandardItem *item3 = new QStandardItem( QString("Item3")); model.invisibleRootItem()->appendRow(item3); tree->setDragDropMode(QAbstractItemView::InternalMove); tree->setModel( &model ); tree->setRootIsDecorated(false); tree->header()->setVisible(false); tree->expandAll(); tree->show(); return app.exec(); }
or python
import sys from PyQt5.QtCore import Qt, QMimeData, QLocale from PyQt5.QtGui import QStandardItemModel, QStandardItem from PyQt5.QtWidgets import QApplication, QMainWindow, QAbstractItemView, QTreeView class SceneTreeModel(QStandardItemModel): def mimeData(self, indexes): print('calling mimeData') name = indexes[0].data() mimedata = QMimeData() mimedata.setText(name) return mimedata def canDropMimeData(self, data, action, row, column, parent): # print(data.text()) print('can drop called on') print(parent.data()) return True def give_model(): model = SceneTreeModel() # create a tree item item1 = QStandardItem('item1') item2 = QStandardItem('item2') item3 = QStandardItem('item3') model.invisibleRootItem().appendRow(item1) item1.appendRow(item2) model.invisibleRootItem().appendRow(item3) return model class UI_MainWindow(QMainWindow): def __init__(self, parent=None): super(UI_MainWindow, self).__init__(parent) Left = 250 Top = 100 Width = 250 Height = 300 self.setGeometry(Left, Top, Width, Height) self.setWindowTitle("MainWindow") self.setLocale(QLocale(QLocale.English, QLocale.UnitedStates)) self.treeView = QTreeView(self) self.treeView.setRootIsDecorated(False) self.treeView.setObjectName("treeView") self.treeView.header().setVisible(False) self.setCentralWidget(self.treeView) self.treeView.setModel(give_model()) self.treeView.setDragDropMode(QAbstractItemView.InternalMove) self.treeView.expandAll() if __name__ == '__main__': MainAppThread = QApplication([]) MainWindow = UI_MainWindow() MainWindow.show() sys.exit(MainAppThread.exec_())
Attachments
Issue Links
- duplicates
-
QTBUG-44939 canDropMimeData on drag enter
-
- Reported
-