How to trigger the edit mode of an item in a QTableView?
Asked Answered
D

2

10

I'm using QTableView and QStandardItemModel now.

In the QTableView, if you double-click a cell, this cell will get into edit mode and you can edit its content.

Now I have a problem, I want to trigger the edit mode of an item by code (by command), what should I do? I cannot find proper function or slot in QTableView or QStandardItemModel. Do I need to emit any signal to get into edit mode?

And which signal I should catch if I want to know when the editing is finish (user press "Enter" or click another items to leave the edit mode)??

Thanks for your help

Drawshave answered 9/9, 2010 at 23:33 Comment(0)
B
10

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]
Bellringer answered 10/9, 2010 at 1:23 Comment(0)
B
15

you should be able to use edit method of the QAbstractItemView class to trigger editing for the given model index.

Pls, see if an example below would work for you:

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

hope this helps, regards

Blurb answered 10/9, 2010 at 1:25 Comment(1)
Thank you so much for your help, it's helpful and the example works :) It's a pithy that I cannot give multiple answers the correct mark, so I can just vote you up ^^Drawshave
B
10

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]
Bellringer answered 10/9, 2010 at 1:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.