PDA

View Full Version : How to focus on QTableView Item



kerim
13th April 2011, 14:01
hi,
hope u can help:
i have QTableView *tableview and i insert a row to it by

tableview->model()->insertRow(0);

Whereby the model is a custom model subclassed from QAbstractTableModel.
Insertion works fine and one can edit the row-content by double-clicking on the freshly created row.

Now, i want the inserted row (this is editable) to get the edit-focus immediately without having to double-click on it to edit it).
how do i do that?
thnx.

Archa4
13th April 2011, 15:19
I have no idea if this will work, but the first thing i would try - emit the signal item doubleclicked...
Again - I don't know if this will work...

kerim
14th April 2011, 08:07
well, i had written that my widget is a QTableView .. itemDoubleClicked() exists
for QListWidget QTableWidget QTreeWidget.

any other ideas :confused:??

Added after 5 minutes:

the signal from QTableView that is emited when item is double clicked is
doubleClicked(..).

unfortunately this is protected. is there a way to emit this without having to subclass QTableView !?!?

Archa4
14th April 2011, 10:30
My idea was - can u do

emit this->itemDoubleClicked(the item u want to edit)

...

ChrisW67
15th April 2011, 00:43
Is the public slot QAbstractItemView::edit() what you are looking for? Read the docs about also using setCurrentIndex() with it.

kerim
15th April 2011, 10:32
thnx chris, thats it.