<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-text-html" lang="x-unicode">
      <p>Hello everyone,</p>
      <p>working on an open source project, I encountered a bug that I
        surprisingly could find no mention of anywhere:</p>
      <p><img src="cid:part1.48B4EB8C.1354B7DF@web.de" alt=""></p>
      <p>It's easy to reproduce: In a QLineEdit with a QCompleter, bring
        up the popup, then use a shortcut to change the focus. You end
        up with two focussed widgets. The single next key stroke will
        still be processed by the line with the completer and the popup
        and ‘a’ cursor will stay visible there.</p>
      <p>My exact input from the GIF:</p>
      <ol>
        <li>F</li>
        <li>Ctrl+F</li>
        <li>Some Os</li>
      </ol>
      <p>The app's source code:</p>
      <blockquote>
        <p><font size="-2" face="Courier New">import sys</font><font
            size="-2" face="Courier New"><br>
            from PyQt5.QtGui import QKeySequence<br>
            from PyQt5.QtWidgets import QApplication, QLineEdit,
            QMainWindow, QWidget, QVBoxLayout, QCompleter, QShortcut</font><font
            size="-2" face="Courier New"><br>
          </font> <font size="-2" face="Courier New"><br>
            class MainWindow(QMainWindow):<br>
          </font> <font size="-2" face="Courier New"><br>
                def __init__(self, *args, **kwargs):<br>
                    super(MainWindow, self).__init__(*args, **kwargs)<br>
                    box = QWidget()<br>
                    self.setCentralWidget(box)<br>
                    layout = QVBoxLayout(box)<br>
                    words = ["foo", "bar"]<br>
                    completer = QCompleter(words)<br>
                    self.line1 = QLineEdit()<br>
                    self.line1.setCompleter(completer)<br>
                    self.line2 = QLineEdit()<br>
                    layout.addWidget(self.line1)<br>
                    layout.addWidget(self.line2)<br>
                    self.shortcut = QShortcut(QKeySequence("Ctrl+F"),
            self)<br>
                    self.shortcut.activated.connect(self.line2.setFocus)</font><font
            size="-2" face="Courier New"><br>
          </font> <font size="-2" face="Courier New"><br>
            app = QApplication(sys.argv)<br>
            window = MainWindow()<br>
            window.show()<br>
            app.exec_()</font></p>
        <p><font size="-2" face="Courier New"><br>
          </font></p>
      </blockquote>
      <p>Apparently in that special case, the QLineEdit with the
        completer doesn't receive a focusOutEvent.</p>
      <p>I could reproduce this bug with PyQt 5.12 to 5.15.1. On 5.9
        with Python 3.7, the shortcut doesn't work with an open popup,
        so the bug isn't reproducable.</p>
    </div>
    <div class="moz-text-html" lang="x-unicode"><br>
    </div>
    <div class="moz-text-html" lang="x-unicode"><br>
    </div>
    <p> Kind regards</p>
    <p>Rumo<br>
    </p>
  </body>
</html>