我有一个插槽,可以创建一个给定点的上下文菜单。但是,无论我使用哪种方法从该点返回位置,table->itemAt(pos) 总是返回 0。有没有办法打印出表格的行/列位置,以便我可以对一些偏移量进行逆向工程?
我尝试了所有可能的排列,并且总是执行“无项目”....
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
}
....
}