QListWidget and item edit event
Anyway is quite easy to reach such result in the following way. First you need to enable the item edit feature by set the required flag as below (pItem is a QListWidgetItem object):
pItem->setFlags(pItem->flags() | Qt::ItemIsEditable);
If you want to connected the closeEditor signal to your slot function you need to use the following call (MyListWidget is a QListWidget object):
connect(MyListWidget->itemDelegate(), SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)), this, SLOT(ListWidgetEditEnd(QWidget*, QAbstractItemDelegate::EndEditHint)));
The slot function will be defined as follow:
void ListWidgetEditEnd(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
This function will be called once the user finish to edit the item. You can get the new string value inserted by the user by simply cast the first param as follow:
NewValue = reinterpret_cast<QLineEdit*>(editor)->text();
As you can note this function return the new item value but doesn't help you in know which item has been modified. For get this info you need to suppose the item just edited will be also a selected item and, in consequence of this, use the corresponding methods from QListWidget object.
Comments
Post a Comment