0

I'm trying to make a interface that's easy to use. I have 2 list one of them list of device already using and the other one is unused ones. So, I'm trying to do add drag and drop feature. Like this. enter image description here

But mine is like this. I cannot drag or drop with QSqlQueryModel.(I used listview)

enter image description here

The codes i wrote for listview like this.

ui->listViewMusteri->setDragEnabled(true);
    ui->listViewMusteri->setAcceptDrops(true);
    ui->listViewMusteri->setDropIndicatorShown(true);
    ui->listViewMusteri->setDefaultDropAction(Qt::MoveAction);

    ui->listViewToplam->setDragEnabled(true);
    ui->listViewToplam->setAcceptDrops(true);
    ui->listViewToplam->setDropIndicatorShown(true);
    ui->listViewToplam->setDefaultDropAction(Qt::MoveAction);
void InformationMusteriDialog::fillListViews() {
    QSqlQueryModel *model = new QSqlQueryModel();
    if(database.isOpen()) {
        QSqlQuery* qry = new QSqlQuery(database);

        qry->prepare("SELECT `Cihaz Seri No` From `cihazisim`");
        qry -> exec();
        model->setQuery(*qry);

        ui->listViewToplam->setModel(model);
    }
}

Please let me know if more information or explanation is required.

  • [The docs](https://doc.qt.io/qt-6/model-view-programming.html#using-drag-and-drop-with-item-views) say that you have to support DnD by your models. You should check the mentioned methods carefully, that they have correct implementation. The docs say for instance: _Note that the model will typically need to provide implementations of the QAbstractItemModel::insertRows() and QAbstractItemModel::setData() functions_, and by default e.g.[QSqlQueryModel::insertRows](https://doc.qt.io/qt-6/qabstractitemmodel.html#insertRows) returns `false`. – absolute.madness Aug 15 '22 at 06:22
  • @absolute.madness yes you're right but i cant even drag the items. I set the dragEnabled true. I dont know why. – Yunus Emre Çınar Aug 15 '22 at 06:50

0 Answers0