Qt - QTableView - Clickable button in table row

cweston picture cweston · Dec 10, 2010 · Viewed 21.1k times · Source

I require a button/link within a table row of a QTableView. This is to open a dialog to allow that row to be edited more efficiently.

After hours of looking on the web I am yet to find a decent example.

I am aware that this is likely to be done using a QItemDelegate, but I am unsure how to have a functional widget within the row without forcing the item into edit mode first.

Any help would be greatly appreciated.

Answer

Ton van den Heuvel picture Ton van den Heuvel · Dec 11, 2010

You can use setIndexWidget for that, see the Qt documentation for more information.

As an example, to embed a push button in the first column of the second row (untested code):

tableView->setIndexWidget(tableView->model()->index(2, 1), new QPushButton);