This should look like this (simple version):
void test_my_ctrl::test_lose_focus()
{
my_ctrl ctrl;
ctrl.setFocus(Qt::TabFocusReason); // first you make sure that focus is in correct place
ctrl.selectAll(); // just in case if it is not selected, so old content will be replaced
QTest::keyClicks(&ctrl, "1.23456789", Qt::NoModifier, 10); // then you type
QCOMPARE
(ctrl.
text(),
QString("1.23456789"));
ctrl.clearFocus();
QTest::qWait(100); // this may be needed to process some of posted events - it may be not needed
QCOMPARE
(ctrl.
text(),
QString("Focus Out"));
}
void test_my_ctrl::test_lose_focus()
{
my_ctrl ctrl;
ctrl.setFocus(Qt::TabFocusReason); // first you make sure that focus is in correct place
ctrl.selectAll(); // just in case if it is not selected, so old content will be replaced
QTest::keyClicks(&ctrl, "1.23456789", Qt::NoModifier, 10); // then you type
QCOMPARE(ctrl.text(), QString("1.23456789"));
ctrl.clearFocus();
QTest::qWait(100); // this may be needed to process some of posted events - it may be not needed
QCOMPARE(ctrl.text(), QString("Focus Out"));
}
To copy to clipboard, switch view to plain text mode
Focus in event should be done in similar manner.
Advanced version should be data driven.
Bookmarks