I have a slot which creates a context menu given a point. However, no matter which method I use to return the position from the point, table->itemAt(pos) always returns 0. Is there any way to print out the tables row/columns positions so I can reverse engineer some offsets?
I tried every permutation possible and 'no item'开发者_运维问答 is always executed....
void test::newContextMenu(const QPoint& point)
{
QPoint pos = table_->viewport()->mapFromGlobal(point); //also tried
//table_->mapFromGlobal(point), table_>viewport()->mapToGlobal(point)
//table_->mapToGlobal(point), and QCursor::pos()
QAction* action tableMenu_->exec(pos);
if(action == XX)
{
QTableWidgetItem* item = table_->itemAt(pos);
if(!item)
{
///no item
}
....
}
Your call to itemAt() should be using point, which is in coordinates local to your widget, not pos which is in global coordinates.
精彩评论