Unsolved Range-based for loop for a QList
-
I hope I get answers for the last two questions I asked, "entirely" and "destructor". Should I make separate threads for them?
@Bonnie
Well, there's no widget set by setItemWidget; I used selectionItems. So you mean that function neither removes any item in the list nor is it needed in the code?It may make sense not to delete the cells of the list while you're still connected to it, but except for that is there any rationale?
So if I use this for that last condition, it's the easiest and best method!else if(button->text().contains("Remove")) { qDeleteAll(list->selectedItems());
-
@tomy Yes, if you open qlistwidget.h, you can see that:
inline void QListWidget::removeItemWidget(QListWidgetItem *aItem) { setItemWidget(aItem, nullptr); }
-
I took a look twice on the task that removeItemWidget does, but couldn't understand this, since the setItemWidget looks complicated.
Will you explain what that remove function does in my code, please. This way it becomes clearer I suppose. -
@Asperamanca said in Range-based for loop for a QList:
Safer to do:
In this case it's not needed - it just adds another loop for nothing.
-
@tomy said in Range-based for loop for a QList:
Will you explain what that remove function does in my code, please.
It removes the widget from the view, nothing more (and exactly what the function name states...)
-
By "from the view" you mean "disappearing" right? But it does nothing to be seen.
-
@tomy As I said, if you haven't called setItemWidget to set a widget, then it does nothing at all.
[ADDED]
And setItemWidget is not that complicated.
You can use it to set a widget to a item, maybe a button, a combox, or any kind of widget.
When the item is visible in the list view, the widget will be shown on the item rect.
So by removeItemWidget, you can remove that widget. -
This post is deleted! -
This post is deleted! -
I've used "addItem" for both the comboBox and listWidget to add items thereby they are visible, but removeItem is for this usage apparently and deleting the selected items will do the job.
Thanks.