Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4571992
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:34:58+00:00 2026-05-21T19:34:58+00:00

ubuntu 10.04, KDE 4.4.5 python 2.6.4 qt 4.6.2 pyqt 4.6.2 I’m trying to create

  • 0

ubuntu 10.04, KDE 4.4.5

python 2.6.4

qt 4.6.2

pyqt 4.6.2

I’m trying to create a QCompleter, which works fine if I just build the QLineEdit.
However if I drop the QLineEdit into a QMainWindow, the QCompleter no longer works.

Here is the LineEdit class

# LineEdit class
import sys
from PyQt4 import QtCore, QtGui

class LineEdit(QtGui.QLineEdit):
    def __init__(self, parent=None):
        super(LineEdit, self).__init__(parent)

        self.setFocusPolicy(QtCore.Qt.StrongFocus)

        self.completer = QtGui.QCompleter(self)
        self.completer.setCompletionMode(QtGui.QCompleter.UnfilteredPopupCompletion)
        self.pFilterModel = QtGui.QSortFilterProxyModel(self)
        self.pFilterModel.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive)
        self.completer.setPopup(self.view())
        self.setCompleter(self.completer)
        self.textEdited[unicode].connect(self.pFilterModel.setFilterFixedString)

    def setModel(self, model):
        self.pFilterModel.setSourceModel(model)
        self.completer.setModel(self.pFilterModel)

    def setModelColumn( self, column ):
        self.completer.setCompletionColumn(column)
        self.pFilterModel.setFilterKeyColumn(column)

    def view(self):
        return self.completer.popup()

    def index( self ):
        return self.currentIndex()

The QCompleter works if I build LinEdit this way

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    model = QtGui.QStandardItemModel()

    for i,word in enumerate(['test', 'blah', 'heh', 'yep']):
        item = QtGui.QStandardItem(word)
        model.setItem(i, 0, item)

    lineEdit = LineEdit()
    lineEdit.setModel(model)
    lineEdit.setModelColumn(0)
    lineEdit.show()
    sys.exit(app.exec_())

This compiles fine, but no longer shows the QCompleter

if __name__ == '__main__':
    class Example(QtGui.QMainWindow):
        def __init__(self):
            QtGui.QMainWindow.__init__(self)

            self.centralWidget = QtGui.QWidget(self)
            self.layout = QtGui.QVBoxLayout(self.centralWidget)

            # can I push this inside the LineEdit class instead?
            model = QtGui.QStandardItemModel()
            for i, word in enumerate(['test', 'blah', 'heh', 'yep', 'hello', 'hi']):
                item = QtGui.QStandardItem(word)
                model.setItem(i, 0, item)

            # Make a LineEdit instance
            self.lineEdit = LineEdit(parent=self.centralWidget)
            self.lineEdit.setModel(model)
            self.lineEdit.setModelColumn(0)
            self.layout.addWidget(self.lineEdit)
            self.setCentralWidget(self.centralWidget)


    app = QtGui.QApplication(sys.argv)
    QtWin = Example()
    QtWin.show()
    sys.exit(app.exec_())
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:34:59+00:00Added an answer on May 21, 2026 at 7:34 pm

    turned out to be quite simple really, hopefully this will help anyone else using PyQt’s QCompleter for auto-completion

    import sys
    from PyQt4 import QtCore, QtGui
    
    class LineEdit(QtGui.QLineEdit):
        def __init__(self, parent, completerContents):
            super(LineEdit, self).__init__(parent)
    
            self.completerList = QtCore.QStringList()
            for content in completerContents:
                self.completerList.append(QtCore.QString(content))
            self.completer = QtGui.QCompleter(self.completerList, self)
            self.completer.setCompletionMode(QtGui.QCompleter.PopupCompletion)
            self.completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
            self.setCompleter(self.completer)
    
    if __name__ == '__main__':
        class Example(QtGui.QMainWindow):
            def __init__(self):
                QtGui.QMainWindow.__init__(self)
    
                self.centralWidget = QtGui.QWidget(self)
                self.layout = QtGui.QVBoxLayout(self.centralWidget)
    
                # Example LineEdit Call
                self.lineEdit = LineEdit(parent=self.centralWidget, completerContents=('test', 'blah', 'heh', 'yep', 'hello', 'hi'))
    
                self.layout.addWidget(self.lineEdit)
                self.setCentralWidget(self.centralWidget)
    
    app = QtGui.QApplication(sys.argv)
    QtWin = Example()
    QtWin.show()
    sys.exit(app.exec_())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On Ubuntu Linux / Gnome, I am trying to use python's wnck binding to
Ubuntu 11.10: $ python Python 2.7.2+ (default, Oct 4 2011, 20:03:08) [GCC 4.6.1] on
I am trying to explore KDE a bit, but many of the tools I
Running Ubuntu 11.04 on vagrant, mac os x 10.7.2. Running chef server. Trying to
On Ubuntu 10.10, I am unable to install lxml to python 2.7. Here are
I have seen through python - Pygtk VS Pyqt VS WxPython VS Tkinter ;
Ubuntu 11.10, Python 2.6. Background: I have an existing Python app that is using
Ubuntu comes with Python 2.7.2+ pre-installed. (I also downloaded the python dev packages.) Because
Running Ubuntu 10, RVM, Passenger and apache2. Trying to configure and get Redmine running.
I recently set up, for a learning exercise, an Ubuntu desktop PC with KDE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.