[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Focus bug with QCompleter
From:       Max Mustermann <dooriiaufat () web ! de>
Date:       2020-10-27 22:40:13
Message-ID: 1632e3ff-d434-170d-de63-c3a6b0923b99 () web ! de
[Download RAW message or body]

Hello everyone,

working on an open source project, I encountered a bug that I
surprisingly could find no mention of anywhere:

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.

My exact input from the GIF:

 1. F
 2. Ctrl+F
 3. Some Os

The app 's source code:

    import sys
    from PyQt5.QtGui import QKeySequence
    from PyQt5.QtWidgets import QApplication, QLineEdit, QMainWindow,
    QWidget, QVBoxLayout, QCompleter, QShortcut

    class MainWindow(QMainWindow):

            def __init__(self, *args, **kwargs):
                    super(MainWindow, self).__init__(*args, **kwargs)
                    box = QWidget()
                    self.setCentralWidget(box)
                    layout = QVBoxLayout(box)
                    words = ["foo", "bar"]
                    completer = QCompleter(words)
                    self.line1 = QLineEdit()
                    self.line1.setCompleter(completer)
                    self.line2 = QLineEdit()
                    layout.addWidget(self.line1)
                    layout.addWidget(self.line2)
                    self.shortcut = QShortcut(QKeySequence("Ctrl+F"), self)
                    self.shortcut.activated.connect(self.line2.setFocus)

    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    app.exec_()


Apparently in that special case, the QLineEdit with the completer
doesn't receive a focusOutEvent.

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.



Kind regards

Rumo


[Attachment #3 (multipart/related)]

[Attachment #5 (text/html)]

<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>

["cepbhdmkmmnfgfeh.gif" (image/gif)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic