How to get the cell coordinates in QTableView
I have created a TableView and on the click i want to get coordinates of the cell in which user has clicked and
create a combobox in that cell & combobox should fix exactly in that cell.How to do this?
Here is my code
QStandardItem* item1 = new QStandardItem("Test1");
QStandardItem* item2 = new QStandardItem("Test2");
Note: tablemodel_PT is of type QStandardItemModel*.
tablemodel_CA->setItem( row, 0, item1 );
tablemodel_CA->setItem( row, 1, item2 );
QComboBox* combo_PT = new QComboBox();
Note:tableView_PT is the object name of the TableView
QPoint point( 5 + ui.tableView_PT->columnViewportPosition ( col ) , ui.tableView_PT->rowViewportPosition(row) );
combo_PT->move( ui.tableView_PT->mapToGlobal(point) );
with above code when I am clicking in any of the cell the combobox is created but it is not place exactly in the cell in which it is clicked it is overlapping with adjacent cells.@
Don't do it that way. Instead, use a delegate that manages the combo box. There are examples in the documentation and on the forum.
Can you please give me the link of the example in documentation.
Maybe You take a look at
These are relevant:
"Sections on delegate classes":http://developer.qt.nokia.com/doc/qt-4.8/model-view-programming.html#delegate-classes
Spinbox delegate "example":http://developer.qt.nokia.com/doc/qt-4.8/itemviews-spinboxdelegate.html
Color delegate factory "example":http://developer.qt.nokia.com/doc/qt-4.8/itemviews-coloreditorfactory.html