QList<QListWidgetItem *> before = getListWidgets();
//TODO remove this one
//TODO do not use the qtest lib, remove it from linker
//QTest::qWait(5000);
QList<QListWidgetItem *> after = getListWidgets();
dbg() << "before" << before;
dbg() << "after" << after;
//TODO: compare before and after, if not equal, emit a signal
}
QList<QListWidgetItem *> MyListWidget::getListWidgets(void) {
QList<QListWidgetItem *> r(findItems("*",Qt::MatchWildcard));
return r;
}
void MyListWidget::dropEvent(QDropEvent* event) {
QList<QListWidgetItem *> before = getListWidgets();
QListWidget::dropEvent(event);
//TODO remove this one
//TODO do not use the qtest lib, remove it from linker
//QTest::qWait(5000);
QList<QListWidgetItem *> after = getListWidgets();
dbg() << "before" << before;
dbg() << "after" << after;
//TODO: compare before and after, if not equal, emit a signal
}
QList<QListWidgetItem *> MyListWidget::getListWidgets(void) {
QList<QListWidgetItem *> r(findItems("*",Qt::MatchWildcard));
return r;
}
To copy to clipboard, switch view to plain text mode
MyListWidget is a QListWidget. What I'm trying to do is emitting a signal when the widgets are really reordered, as dropEvent sometimes occurs even when the order is the same. The problem is that the list "after" contains one more element, as QListWidget::dropEvent() duplicates the QListWidgetItem before moving it to the new position (QTest::qWait() proves it).
My question is: how, where or when to attempt to get the state of the list widgets after the copy has been removed and everything is in place, so that a simple
if(after != before) emit widgetsReordered;
if(after != before) emit widgetsReordered;
To copy to clipboard, switch view to plain text mode
will do the job ?
Bookmarks