From the book I'm reading:
By default, QListWidget is read-only. If we wanted the user to edit the items, we could set the view's edit triggers using QAbstractItemView::setEditTriggers(); for example, a setting of QAbstractItemView::AnyKeyPressed means that the user can begin editing an item just by starting to type.
So, I call the function in my code:
ui->listWidget->setEditTriggers(QAbstractItemView::AnyKeyPressed);
But when I select an item and start typing, nothing happens.
It turns out that the items themselves also have an editable flag, so after adding them I had to iterate all of them and set it. Now it's working.
// set the editable flag for each item
for (int ii = 0; ii < ui->listWidget->count(); ii++) {
ui->listWidget->item(ii)->setFlags(ui->listWidget->item(ii)->flags() | Qt::ItemIsEditable);
}
// set the editable triggers for the list widget
ui->listWidget->setEditTriggers(QAbstractItemView::AnyKeyPressed);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With