<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Overriding QCompleter popup position]]></title><description><![CDATA[<p dir="auto">I've asked on <a href="https://stackoverflow.com/questions/64314567/overriding-qcompleter-popup-position" target="_blank" rel="noopener noreferrer nofollow ugc">Stackoverflow</a> so maybe this is bad form but i'm not getting any response there so hoping someone can help here.</p>
<p dir="auto">There have been similar questions asked about overriding the QCompleter popup position but i'll still not found a working solution. I simply want to move the popup down around 5px (I have some specific styling requirements)</p>
<p dir="auto">I've tried subclassing a QListView and using that as my popup using setPopup(). I then override the showEvent and move the popup down in Y. I also do this on the resizeEvent since I believe this is triggered when items are filtered and the popup resizes. However this doesn't work.. I then used a singleshot timer to trigger the move after 1ms. This does kind of work but it seems quite inconsistent - the first time it shows is different to subsequent times or resizing.</p>
<p dir="auto">Below is my latest attempt (trying to hack it by counting the number of popups..), hopefully someone can show me what i'm doing wrong or a better solution</p>
<pre><code>import sys
import os
from PySide2 import QtCore, QtWidgets, QtGui

class QPopup(QtWidgets.QListView):
    def __init__(self, parent=None):
        super(QPopup, self).__init__(parent)

        self.popups = 0

    def offset(self):
        y = 3 if self.popups &lt; 2 else 7
        print('y: {}'.format(y))
        self.move(self.pos().x(), self.pos().y() + y)

        self.popups += 1

    def showEvent(self, event):
        print('show')
        # self.offset()
        QtCore.QTimer.singleShot(1, self.offset)

    def resizeEvent(self, event):
        print('resize')
        # self.offset()
        QtCore.QTimer.singleShot(1, self.offset)

class MyDialog(QtWidgets.QDialog):
    def __init__(self, parent=None):
        super(MyDialog, self).__init__(parent)

        self.create_widgets()
        self.create_layout()
        self.create_connections()

    def create_widgets(self):
        self.le = QtWidgets.QLineEdit('')

        self.completer = QtWidgets.QCompleter(self)
        self.completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
        self.completer.setCompletionMode(QtWidgets.QCompleter.PopupCompletion)
        self.completer.setMaxVisibleItems(10)
        self.completer.setFilterMode(QtCore.Qt.MatchContains)
        self.completer.setPopup(QPopup())

        popup = QPopup(self)
        self.completer.setPopup(popup)

        self.model = QtCore.QStringListModel()
        self.completer.setModel(self.model)

        self.le.setCompleter(self.completer)

        self.completer.model().setStringList(['one','two','three'])

    def create_layout(self):
        main_layout = QtWidgets.QVBoxLayout(self)

        main_layout.addWidget(self.le)

    def create_connections(self):
        pass

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)

    my_dialog = MyDialog()

    my_dialog.show()  # Show the UI
    sys.exit(app.exec_())
</code></pre>
]]></description><link>https://forum.qt.io/topic/119929/overriding-qcompleter-popup-position</link><generator>RSS for Node</generator><lastBuildDate>Sat, 31 Oct 2026 22:12:26 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/119929.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 14 Oct 2020 08:44:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Overriding QCompleter popup position on Wed, 14 Oct 2020 18:43:12 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">You might have a starting point with this <a href="https://stackoverflow.com/a/57867721/5843716" target="_blank" rel="noopener noreferrer nofollow ugc">stack overflow answer</a>.</p>
]]></description><link>https://forum.qt.io/post/622256</link><guid isPermaLink="true">https://forum.qt.io/post/622256</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 14 Oct 2020 18:43:12 GMT</pubDate></item></channel></rss>