How to call item edit mode in QTableView?

Now I am using QTableView and QStandardItemModel.

In QTableView, if you double-click a cell, that cell will go into edit mode and you can edit its contents.

Now I have a problem, I want to call the element editing mode by code (by command), what should I do? I cannot find a suitable function or slot in QTableView or QStandardItemModel. Do I need to emit any signal to go into edit mode?

And what signal should I catch if I want to know when the editing is finished (the user presses "Enter" or press other elements to exit the editing mode)

thanks for the help

+7
user-interface qt qt4 qtableview
source share
2 answers

See:

void QAbstractItemView::edit ( const QModelIndex & index ) [slot] void QAbstractItemView::closeEditor ( QWidget * editor, QAbstractItemDelegate::EndEditHint hint ) [virtual protected slot] void QAbstractItemView::editorDestroyed ( QObject * editor ) [virtual protected slot] 
+7
source share

you can use the editing method of the QAbstractItemView class to start editing for a given model index.

Pls see if the below example will work:

 QModelIndex index = ui->tableView->model()->index(0, 0, QModelIndex()); ui->tableView->edit(index); 

hope this helps, believes

+10
source share

All Articles