Recently, I saw a topic about QTest::mouseClick LeftButton(How can you edit a QTableView cell from a QTest unit test?),I trid it and succeeded.
Now I need to simulate a RightButton-Click action and get the customContextMenuRequested, I used the same way to do it, however it failed.Here is the code:
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
I find QTest is not friendly enough, for some cases are not like you think.
Any suggestions would be greatly appreciated!