Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTreeWidget - multiple columns d&d



  • I have a QTreeWidget with tree columns:

    @void MyTree::AddNewElement()
    {
    QTreeWidgetItem* treeItem = new QTreeWidgetItem( this, 0 );
    treeItem->setText( 0, "someText" );
    setItemWidget( treeItem, 1, new QToolButton( this ) );
    setItemWidget( treeItem, 2, new QToolButton( this ) );
    }@

    for this widget I want to implement d&d so all the columns should keep their content. Right now when I'm d&d only the text column keeps the content. How should I do it right?

    Thanks!



  • Drag'n'drop for item widgets is not supported out of the box.

    You would have to go with QTreeView and a customized model to make this work.



  • yes you're right about this, I need to do some more studying :) , I found a nice example "here":http://www.java2s.com/Code/Cpp/Qt/QTreeViewdraganddrop.htm



  • Does setting the following work?
    @
    MyTree::MyTree(...)
    {
    setDragEnabled(true);
    setAcceptDrops(true);
    setDragDropMode(QAbstractItemView::InternalMove);

    ...
    }
    @



  • Looking at the source code of the Qt libs, the widgets (resp. their pointers) plainly don't make their way into the dragged data.


Log in to reply