Reordering ListWidgetItem Items.
-
Hey,
Yes I want to get the Qlabel text each time I do reordering.
I want to check the result of the reordering by checking the text on each label, which should be changed each time.
After the label reordering I check the list item again, but the problem is I can only get the initial order.This is the code:
@for (int i = 0 ; i< list->count(); i++){
QListWidgetItem* item = dynamic_cast <QListWidgetItem*>(list->item(i)); QLabel* label = dynamic_cast<QLabel*> (list->itemWidget(item)); std::cout<<"The text after reordering :"<<label->text().toStdString()<<std::endl;}
@
Thank you,
-
There's something strange here, why are you casting to QLabel ?
-
QListWidget doesn't create QLabel for its items. You can get the text directly from the item.
-
okay I deleted the Qlabel.
But the problem is still there. I'm wondering why each after I do reordering, and I click proceed the Qlistwidget has the initial ordering, and it does not update its items according to the new reordering from the GUI.@
void Gui::qtReactOnProceed(){for (int i = 0 ; i< list->count(); i++){
QListWidgetItem* item = dynamic_cast <QListWidgetItem*>(list->item(i));
std::cout<<"The row:"<<item->text().toStdString()<<std::endl;
}
}
@Actually I do not know how the DragandDropMode updates the Qlistwidget, is it done by default.
Thank you again.
-
How are you doing the reordering ?
-
I’m reordering By using the drag and drop mode for the listwidget.
I have created the listwidget then enabled the drag and drop mode for it.After the user do reordering he clicks a button so in that action I’m reading the list again to check its items "new reorder for the items".
Is that the right way.
Does the Gui refresh itself, or I have to add the list again to Gui each time I do reordering.
I hop you a clear get an idea about what I trying to do.
Thank you again. -
Can you show the code where you setup the drag and drop behavior ?
-
Hello,
Thank you,
I could solve the problem, it was not in the qlistwidget, actually the qlistwidget with dragnaddrop mode works fine.But the problem was in calling the function, it was called many times and in that case more than one list are created, and added on the top of each other, accordingly I had incorrect result from the list.
-
You're welcome !
Nice you found out and thanks for sharing.
Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)