How to Create, Show & All about text label in PyQt5

In this tutorial, I'm going to explain to you about creating text on a window object in PyQt5. The text object is a common function used in Applications. You can learn about the below subtopics in this post, 

    1. Creating a text and showing it inside a PyQt5 window

    2. Adding CSS styles to text 

    3. How to make a selectable text

Creating A Text

  I'm using QLabel() function to create texts. because it is the easiest way to make a text object. Also, it is supported to display Unicode and emojis. 

 self.Text = QLabel("Sci-Tech Guide Blogspot.com", self)
 self.Text.setGeometry(210, 200, 200, 20)




Adding Styles to Text

  You can adjust the text size, font family, font color, text background, and much more styles using "setStyleSheet()" function in PyQt5. 

Resize the text

   setStyleSheet("font-size: 20px;") -- You can adjust the size as you want

Set a Font Color

   setStryleSheet("color: #F0FFF0;") -- You can adjust the color as you want





Making Text Selectable & Copyable

   If you try to copy or select the text we created, You'll see that we can't select it. Now, I'm going to explain to you how to make it selectable and copyable. 

syntax that  I'm using: self.Text.setTextInteractionFlags(Qt.TextSelectableByMouse)



Now, you can select and copy the text. This is all I'm explaining for this post. If you have a problem with this, feel free to comment below.

Post a Comment

0 Comments