QListWidget :: setEditTriggers (QAbstractItemView :: AnyKeyPressed) does not work

From the book I'm reading:

By default, QListWidget is read-only. If we want the user to edit the elements, we could set view editing triggers using QAbstractItemView :: setEditTriggers (); for example, setting QAbstractItemView :: AnyKeyPressed means that the user can start editing an element that is just starting to enter.

So, I call the function in my code:

ui->listWidget->setEditTriggers(QAbstractItemView::AnyKeyPressed); 

But when I select an item and start typing, nothing happens.

+6
source share
1 answer

It turns out that the elements themselves also have a mutable flag, so after adding them, I had to sort through all of them and install. Now it works.

 // 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); 
+6
source

All Articles