Home > Software engineering >  How to do action when QStringListModel changed?
How to do action when QStringListModel changed?

Time:08-19

Basically, I have 2 listviews and when I drag&drop one listview to another one,I want to execute a sql query.

I tried to override dropEvent but it does not getting called. However the drop action happening.(I go through the model data with for loop and I can print the items in the model)

enter image description here

Why the dropEvent not called when drop happens ?

protected:
    void mousePressEvent(QMouseEvent *event)override;
    void mouseMoveEvent(QMouseEvent *event)override;
    void dragEnterEvent(QDragEnterEvent *event)override;
    void dragMoveEvent(QDragMoveEvent *event)override;
    void dragLeaveEvent(QDragLeaveEvent *event)override;
    void dropEvent(QDropEvent *event)override;
void InformationMusteriDialog::dropEvent(QDropEvent *event) {
    QMessageBox::information(this,"x","xss");
    event->acceptProposedAction();
}

CodePudding user response:

I solve the problem if anyone curious about this problem.

I thought I can connect QStringListModel with SIGNAL and SLOT.

connect(ui->listViewMusteri->model(),&QAbstractItemModel::dataChanged,this, &InformationMusteriDialog::listViewMusteriChanged);      
connect(ui->listViewToplam->model(),&QAbstractItemModel::dataChanged,this, &InformationMusteriDialog::listViewToplamChanged);

When model's data is changed, you can do something.

(btw I'm keep searching about DnD methods.)

  • Related