Qt-interest Archive, December 2007
reordering QListWidgetItems of a QListWidget
Message 1 in thread
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;
}
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;
will do the job ?
--
[ signature omitted ]