0% found this document useful (0 votes)
11 views2 pages

doc_qt_io_qtforpython_6_tutorials_basictutorial_widgets_html

This document provides a simple example of a 'Hello World' application using PySide6, demonstrating the basic structure of a QtWidgets application. It explains the necessary imports, the creation of a QApplication instance, and the use of QLabel to display text. The document emphasizes the importance of calling app.exec() to start the Qt main loop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

doc_qt_io_qtforpython_6_tutorials_basictutorial_widgets_html

This document provides a simple example of a 'Hello World' application using PySide6, demonstrating the basic structure of a QtWidgets application. It explains the necessary imports, the creation of a QApplication instance, and the use of QLabel to display text. The document emphasizes the importance of calling app.exec() to start the Qt main loop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Your First QtWidgets Application

As with any other programming framework, you start with the traditional “Hello World” program.

Here is a simple example of a Hello World application in PySide6:

import sys
from PySide6.QtWidgets import QApplication, QLabel

app = QApplication(sys.argv)
label = QLabel("Hello World!")
label.show()
app.exec()

When you execute it the code, the application will look like:

For a widget application using PySide6, you must always start by importing the appropriate class from
the PySide6.QtWidgets module.

After the imports, you create a QApplication instance. As Qt can receive arguments from command line,
you may pass any argument to the QApplication object. Usually, you don’t need to pass any arguments
so you can leave it as is, or use the following approach:

app = QApplication([])

Explore our developer-friendly HTML to PDF API Printed using PDFCrowd HTML to PDF
After the creation of the application object, we have created a QLabel object. A QLabel is a widget that
can present text (simple or rich, like html), and images:

# This HTML approach will be valid too!


label = QLabel("<font color=red size=40>Hello World!</font>")

Note

After creating the label, we call show() on it.

Finally, we call app.exec() to enter the Qt main loop and start to execute the Qt code. In reality, it is only
here where the label is shown, but this can be ignored for now.

Explore our developer-friendly HTML to PDF API Printed using PDFCrowd HTML to PDF

You might also like