PyQt5 Creating QCompleter Practical Example

In this PyQt5 article we are going to learn about Creating QCompleter Practical Example.  the QCompleter object is used to provide auto-completions when text is entered into some widgets such as the LineEdit or ComboBox. when user begins to type, the model content is matched and suggestions are provided.

 

 

What is QCompleter in PyQt5 ?

QCompleter is a widget provided by PyQt5 that provides automatic completion for user input based on provided list of possible values. it is typically used in text input fields such as QLineEdit or QTextEdit to help users enter values more efficiently and accurately.

When QCompleter widget is attached to text input field, it provides drop down list of possible completions based on the current input. after that the users can select completion from the list or continue typing their own input. QCompleter widget can be customized to match the specific needs of the application, including:

  • Providing a custom list of possible completions.
  • Customizing the appearance and behavior of the drop down list.
  • Handling user input events such as filtering the list based on the current input or selecting a completion.

QCompleter is often used in applications that require data entry, such as address books, search fields, or form input. It can also be used to provide autocompletion for command-line interfaces or other text based interfaces.

 

 

 

Also you can read more Python GUI articles in the below links

 

 

 

 

These are the imports that we need for this article.

 

 

 

 

This is our main window class that extends from window class and we initialize some window requirements like title and geometry . also we call our InitWindow() method in this class.

 

 

 

 

These line of codes are setting of our window geometry , window title and window icon. also we have called our Completer() method in here.

 

 

 

 

So now in here we create the object of QVBoxLayout and we have created a list of countries, because we want to add that list in our completer. also we need to create QLineEdit object.

 

 

 

 

 

In here we have added our QLineEdit in the vbox layout and we set the vbox layout to the main window.

 

 

 

 

Also every PyQt5 application must create an application object. 

 

 

 

Finally, we enter the mainloop of the application. The event handling starts from this point.

 

 

 

 

Complete source for the QCompleter

 

 

 

 

Run the code and this is the result

PyQt5 Creating QCompleter Practical Example
PyQt5 Creating QCompleter Practical Example

 

 

 

Also you can watch the complete video for this article

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×