1

最近看到一个关于QTest::mouseClick LeftButton( How can you edit a QTableView cell from a QTest unit test? )的话题,试了一下,成功了。

现在我需要模拟一个 RightButton-Click 动作并获取 customContextMenuRequested,我使用相同的方法来完成它,但是它失败了。这是代码:

int xPos = m_pTableView->columnViewportPosition( 2 ) + 5;
int yPos = m_pTableView->rowViewportPosition( 3 ) + 10;

// Retrieve the viewport of the table view
QWidget* pViewport = m_pTableView->viewport();

// I tried serveral combinations
#if 1
QTest::mouseClick ( pViewport, Qt::LeftButton, NULL, QPoint( xPos, yPos ) );
QTest::mouseClick( pViewport, Qt::RightButton, NULL, QPoint( xPos, yPos ) );
#else 
QTest::mouseClick ( pViewport, Qt::LeftButton, NULL, QPoint( xPos, yPos ) );
QTest::mouseClick( pViewport, Qt::RightButton, NULL, QPoint( xPos, yPos ) );
QTest::mouseClick( pViewport, Qt::RightButton, NULL, QPoint( xPos, yPos ) );
#endif

我发现 QTest 不够友好,因为有些情况不像你想的那样。

任何建议将不胜感激!

4

0 回答 0