PyQt5 Creating QLineEdit With returnPressed Signal

In this PyQt5 article i want to show you PyQt5 Creating QLineEdit With returnPressed Signal , also iam going to show you how you can connect returnPressed signal of QLineEdit with Slot. a line edit allows the user to enter and edit a single line of plain text with a useful collection of editing functions, including undo and redo, cut and paste, and drag and drop (see setDragEnabled()). By changing the echoMode() of a line edit, it can also be used as a “write-only” field, for inputs such as passwords.

 

 

Join PyQt5 Full Course for Free

PyQt5 Course

 

 

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

 

 

 

First we need some imports.

 

 

 

After that we are going to create our main Window class that extends from QWidget. and in the constructor of the class we need to add some requirements of the window like set window title, window icon and window geometry.

 

 

 

In here we are going to create a QHBoxLayout object with QLineEdit, also we have set font size and font style for the lineedit.

 

 

 

We have connected the returnPressed signal of QLineEdit with the onPressed() method that we will create.

 

 

 

In here we have created a QLabel, also we have set the font for the label.

 

 

 

We need to add our label and lineedit in the hbox layout, also we need to set the layout for our main window. if you don’t do this you will not see any widget in the window.

 

 

 

Also we need to show the window.

 

 

 

Now we create our onPressed() method that we have already connected this with the signal of QLineEdit. basically in this method we just get the text from the line edit and we set that to the label.

 

 

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 code PyQt5 Creating QLineEdit With returnPressed Signal

 

 

 

Run the complete code and this will be the result.

PyQt5 Creating QLineEdit With returnPressed Signal
PyQt5 Creating QLineEdit With returnPressed Signal

 

 

 

 

 

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
×