Archived:How to use QLabel
In this article we will see how to use QLabel to display text or an image. No user interaction functionality is provided. The visual appearance of the label can be configured in various ways, and it can be used for specifying a focus mnemonic key for another widget.
- This function setBuddy(QWidget) is used to set the buddy of any particular widget.
- Without Function
- With using setBuddy(QWidget)
- To set the text Format.
- Specifies how the label should interact with user input if it displays text.
- To set the frame style of label.
- For more Function See Here
Here is the complete code that will help the beginners.
In the above example 1st and 2nd line include the definitions of the QApplication and QLabel classes. For every Qt class, there is a header file with the same name (and capitalization)as the class that contains the class’s definition.
5th line creates a QApplication object to manage application-wide resources. The QApplication constructor requires argc and argv because Qt supports a few command-line arguments of its own. 6th line creates a QLabel widget that displays “Hello Qt!”. Whatever widgets are created that all are invisible by defaults so next lline will set the widgets to visible. Last line passes control of the application to Qt. At this point, the program waits for user actions such as mouse clicks and key presses.
- This is used to set the image on the label and also shows how scale the content of label.Scaling QPixmap image