When trying to edit in QTableView using simulated events, there are a few things to consider:
QTableView does not display its cells directly; it does this with viewport () . Similarly, a double-click event should be sent to the viewer instead of the table view itself.
Now when you do
QTest::mouseDClick( m_pTableView->viewport(), Qt::LeftButton, NULL, QPoint( xPos, yPos ) );
the cell will be selected, but not in edit mode (unlike the double-click initiated by a person who instantly puts the cell in edit mode, even if there was no focus in the table view before). However, if you add one click to the same place before double-clicking, it will work!
If you then sent [End] to the viewport, the cursor would not have moved to the end of the contents of the table cell, but instead select the last cell in the current row.
To change the contents of a table cell, you must send this event to the current editor widget. The easiest way to do this is to use QWidget :: focusWidget ()
QTest::keyClick( m_pTableView->viewport()->focusWidget(), Qt::Key_End );
Note that using this type may be unsafe, although since focusWidget () may return NULL.
With this knowledge, the test case can be programmed as follows:
(Note: if you want to verify this, you can add the QTest :: qWait (1000) commands after each event)
If you use the _data () functions, as described here , note that you cannot get focusWidget () while creating the data, I solved this problem by creating my own ITestAction interface ITestAction only a clean virtual execute () function. Then I added subclasses with a similar constructor, like the QTest::mouseClick(...) etc functions. These classes simply call the QTest functions, but use either the widget itself or the focus widget as a parameter, depending on the additional Boolean flag. The _data () slot then stores a QList <ITestAction *> for each row of data, and the actual test slot iterates over this list and calls execute () for each element before performing the check.