开发者

QTableWidgetItem.itemAt(pos) always returns 0 on contextMenu request

开发者 https://www.devze.com 2023-03-30 17:03 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号