Qt:QAbstractItemView::NoEditTriggers 的反义词是什么?

Qt: What is the opposite of QAbstractItemView::NoEditTriggers?

我想在某些信号上启用和禁用 QTableView 小部件的编辑。我可以通过以下方式禁用它:

table->setEditTriggers(QAbstractItemView::NoEditTriggers);

但是如何重新打开它?

如果打印 editTriggers:

qDebug()<< table->editTriggers();

得到:

QFlags<QAbstractItemView::EditTriggers>(DoubleClicked|EditKeyPressed|AnyKeyPressed)

所以可以假定默认状态是:

QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed | QAbstractItemView::AnyKeyPressed

或者更简单的解决方案是将开始时的状态保存为class的成员:

*.h

// ...
private:
    QAbstractItemView::EditTriggers default_trigger;

*.cpp

// constructor
default_trigger = table->editTriggers();

然后在您的函数中使用:

if(table->editTriggers() == QAbstractItemView::NoEditTriggers)
    table->setEditTriggers(default_trigger);
else
    table->setEditTriggers(QAbstractItemView::NoEditTriggers);