Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to undo edit of qstandarditem in pyqt?


Asked by Elora Noble on Dec 10, 2021 FAQ



Using the identical question asked about QListWidgets as a guide, I am trying to make a QStandardItemModel in which I can undo the edit of an item. As can be seen in the SSCCE below, I'm pretty much copying the example exactly, but with some minor tweaking because currentItemChanged isn't available for QStandardItemModel.
Accordingly,
The item's children are not copied. When subclassing QStandardItem, you can reimplement this function to provide QStandardItemModel with a factory that it can use to create new items on demand. See also QStandardItemModel::setItemPrototype () and operator= ().
Furthermore, QModelIndex QStandardItem:: index () const Returns the QModelIndex associated with this item. When you need to invoke item functionality in a QModelIndex -based API (e.g. QAbstractItemView), you can call this function to obtain an index that corresponds to the item's location in the model.
In fact,
By default, items are enabled, editable, selectable, checkable, and can be used both as the source of a drag and drop operation and as a drop target. Each item’s flags can be changed by calling setFlags (). Checkable items can be checked and unchecked with the setCheckState () function.
Likewise,
QList < QStandardItem *> QStandardItem:: takeRow (int row) Removes row without deleting the row items, and returns a list of pointers to the removed items. For items in the row that have not been set, the corresponding pointers in the list will be nullptr .