0
votes

I have one QTreewidget which displays a list of objects only in top level. So you can think it as list widget. Because QListWidget doesn't support multi-column, I use QTreeWidget.

I controlled drag-and-drop related properties like this.

dragEnabled  = true

dragDropOverwriteMode = true

dragDropMode = InternalMove

The problem is when I drag and drop items in this treewidget, dropped item goes into child of other item, and this is not what I want. I need only one top level, because what I need is list , not tree.

Is there any way to implement only re-ordering of items? If not, Can you provide me other way instead of QTreeWidget?

1
Have you tried QTableWidget ?asitdhal
oh, I solved this problem using QTreeWidget. thank u.Denis Turgenev

1 Answers

1
votes

Using following code, I could make sortable, multi-column, context-menu triggerable list using QTreeView.

    ui->sensorTreeView->setColumnCount(2);
    ui->sensorTreeView->setSelectionMode(QAbstractItemView::MultiSelection);
    ui->sensorTreeView->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->sensorTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
    ui->sensorTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->sensorTreeView->setItemsExpandable(false);
    ui->sensorTreeView->setExpandsOnDoubleClick(false);


    ui->sensorTreeView->setDragEnabled(true);
    ui->sensorTreeView->viewport()->setAcceptDrops(true);
    ui->sensorTreeView->setDropIndicatorShown(true);
    ui->sensorTreeView->setDragDropMode(QAbstractItemView::InternalMove);