QTableWidgetItem.itemAt(pos) 在 contextMenu 请求上始终返回 0
我有一个插槽,可以在给定点的情况下创建上下文菜单。但是,无论我使用哪种方法从该点返回位置,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
}
....
}
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
}
....
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您对 itemAt() 的调用应该使用 point,它位于小部件的本地坐标中,而不是位于全局坐标中的 pos。
Your call to itemAt() should be using point, which is in coordinates local to your widget, not pos which is in global coordinates.
尝试使用:
Try to use: