qt - QTableView - set the first column as "read only" -
I have a QTableView based on QTandardItemModel. I want to set the first column as "read only" and all other columns are editable.
I am not an expert on Qt and OOP, I searched around the web and in the QT-document and I 'I understand that I am going to change my model's flag (CONST COMEDAL INDEX & INDEX) function again. Need to do it, but I do not know how and where to re-execute.
Thanks in advance!
You should create a new category derived from QStandardItemModel
, the Result Mode Flags
and use your new class instead of the standard one.
class MyModel: public QStandardItemModel {public: virtual Qt :: ItemFlags flag (const QModelIndex and index) const override {Qt:: item flag result = QStandardItemModel :: flags (index); If (index.column () == 0) // 0 is the first column! {Results & amp; = ~ Qt :: ItemIsEditable; } Return results; }}
Another way to do this:
- Create a new class from QStandardItem
, reimplement flag
By the same way - Call QStandardItemModel :: setItemPrototype
with an example of a new class - this is a bit more complicated because you will need to re-implement the method QStandardItem :: Clone
as well.
Comments
Post a Comment