Tried clearFocus but that didn't work. According to the docs

If the widget has active focus, a focus out event is sent to this widget to tell it that it is about to lose the focus.
Maybe "about to lose focus" is different from actually losing focus? I don't see how I can check setFocus without having a way to remove focus

For the record, I've tested my control in a test app to make sure it actually works, which it does. All I wish to do now is enshrine this behavior in a unit test.

Here's a more complete yet still simple example of what I'm after:

my_ctrl header
Qt Code:
  1. class my_ctrl : public QLineEdit
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. my_ctrl(QWidget * parent = 0);
  7. ~my_ctrl();
  8.  
  9. protected:
  10. virtual void focusInEvent(QFocusEvent * e);
  11. virtual void focusOutEvent(QFocusEvent * e);
  12. };
To copy to clipboard, switch view to plain text mode 

my_ctrl implementation
Qt Code:
  1. my_ctrl::my_ctrl(QWidget * parent)
  2. : QLineEdit(parent)
  3. {}
  4.  
  5. my_ctrl::~my_ctrl()
  6. {}
  7.  
  8.  
  9. void my_ctrl::focusInEvent(QFocusEvent * e)
  10. {
  11. setText("Focus In");
  12. QLineEdit::focusInEvent(e);
  13. }
  14.  
  15. void my_ctrl::focusOutEvent(QFocusEvent * e)
  16. {
  17. setText("Focus Out");
  18. QLineEdit::focusOutEvent(e);
  19. }
To copy to clipboard, switch view to plain text mode 

test code
Qt Code:
  1. class test_my_ctrl : public QObject
  2. {
  3. Q_OBJECT
  4. private slots:
  5. void test_lose_focus();
  6. };
  7.  
  8.  
  9.  
  10. void test_my_ctrl::test_lose_focus()
  11. {
  12. my_ctrl ctrl;
  13.  
  14. QTest::keyClicks(&ctrl, "1.23456789");
  15.  
  16. QCOMPARE(ctrl.text(), QString("1.23456789"));
  17.  
  18. ctrl.clearFocus(); //doesn't work
  19.  
  20. QCOMPARE(ctrl.text(), QString("Focus Out")); //fails with Actual (ctrl.text()): 1.23456789
  21.  
  22. }
  23.  
  24.  
  25. QTEST_MAIN(test_my_ctrl)
  26. #include "main.moc"
To copy to clipboard, switch view to plain text mode