Test scripts with Python Qt

Stefan Heinrich

26/07/2021

Qt (like "cute" in English) is a C++-based framework of modules and libraries for cross-platform software development. Wrapper libraries, called "bindings," are used to enable the Qt framework to be used in Python. Python Qt enables the programming of applications with intuitive graphical user interfaces in a comparatively short time.

Anyone searching for Python Qt will primarily come across "Qt for Python," the official name of the PySide binding development project. Alternatively, there is another set of Python bindings, PyQt, which was more widely used for a long time due to its more stable implementation and more frequent updates. Today, the two bindings are very similar, and the differences are no longer as clear as they were a few years ago. Licensing is the most relevant difference for most users. PyQt is available under the GNU GPL v3 and an additional commercial license, while PySide can be used under an LGPL license. Because the LGPL license has less stringent requirements (e.g., publication of the source code), PySide is more often suitable for commercial use than PyQt. Both bindings can be used for non-commercial or personal applications.

What do we use Python Qt for?

Using Python Qt Test scripts and graphical user interfaces can be created in a short amount of time. In hardware and software tests, these accelerate the test process and simplify test execution. The script shown in the right image, for example, simulates the serial communication of a flow sensor during software tests on a medical device. The actual sensor is not required for the test, which simplifies the configuration of specific system states. Entering specific limit values allows alarm signals to be triggered or other algorithms based on the sensor's measurement data (control, etc.) to be tested. Parameters such as error states, temperatures, or the sensor's serial number can also be manipulated as required during the test, without the need for a complicated test setup.

Another practical application is the remote control of measuring equipment. For example, the script shown below can be used to control a laboratory power supply and an electronic load via a network connection. Certain hardware tests can also be performed this way from outside the lab or from a home office. With sufficiently complex programs, complete test automation can also be achieved, if necessary.

What do you need to get started?

An installation of Python and basic programming knowledge are basically all you need to get started with Python Qt. The installation files for various Python versions, associated documentation, and even some tutorials can be obtained from the Python website (www.python.org). Please ensure that the following option is enabled during installation, otherwise the system will not be able to assign Python-specific command line commands:

You then also have access to pip, the "Package Installer for Python." To install PySide or PyQt, use the "pip install" command, as in the following example:

If errors occur despite everything when running pip, running the command line as an administrator can help. Documentation and tutorials for Python Qt are available on the PyQt and PySide websites, among others (see related links). It's often also worthwhile to consult the Qt C++ documentation directly to gain a better understanding of the Python Qt implementation.

Virtual Python development environments (venv/virtualenv) are useful if you plan to use different versions of the bindings in multiple projects. They significantly simplify the organization of individual projects. Finally, at least a text editor is necessary to write Python code, but it's more structured with a dedicated development environment (IDE). Which IDE you choose depends largely on personal preference.

Atom as a Python IDE

Regardless of whether Visual Studio, PyCharm or IDLEUsing a development environment makes programming easier with numerous practical features. Some text editors enable a similar workflow using various add-ins. I personally have set up the text editor Atom as my Python IDE for upcoming Python Qt projects. Versatile extensions are available for Atom to customize the user interface and appearance or expand the text editor's features:

The following or similar packages should at least be installed for this purpose (File -> Settings -> Install):

  • script (for executing code in Atom)
  • linter-flake8 (code analysis)
  • python debugger

Interesting for workflow and user interface:

  • python-autopep8 (automatic formatting)
  • minimap (display of the code overview on the right side)
  • autocomplete-python (Python-specific auto-completion)
  • file icons (clearer icons for different file types)

Information on necessary settings can be found in the README section of the respective package.

Using Qt Designer

If you don't want to write the entire code of a script by hand, using Qt Designer is a good option. Since the software allows you to place UI elements using drag and drop, it can speed up the creation of user interfaces. The resulting .ui files can then be used to generate Python code, which you only need to fill with the necessary logic to implement the actual software function.

Qt Designer is part of the PyQt5-Tools package and can be installed using the command line command “pip install pyqt5-tools.” Depending on the operating system, Qt Designer will then be located in the Python installation folder (in my case, …\Python39\Lib\site-packages\qt5_applications\Qt\bin\designer.exe) to find.

Further links

For further information or project suggestions using Python Qt, please feel free to contact us. Additional information and tutorials can also be found at the following links if you'd like to explore Python Qt yourself:

about Python: https://www.python.org/
about Qt: https://wiki.qt.io/About_Qt
about PySide / Qt for Python: https://doc.qt.io/qtforpython
about PyQt: https://riverbankcomputing.com/software/pyqt/intro


Written by Stefan Heinrich

Stefan Heinrich has been part of the MEDtech engineering team since October 2020. He primarily works as a hardware developer.


More articles

  • 26/11/2025
  • General, Hardware, Standards, Quality, Testing

Why EMC testing is vital in medical technology: Imagine a patient is lying in the hospital during critical monitoring. Suddenly, a visitor's smartphone rings – and the monitoring device... ...

Read more
  • 20/11/2025
  • General, Hardware, Quality, Technology, Testing

Have you ever considered sourcing inexpensive components from China? The temptation is strong, we know that. And we've already gained some experience, from which I... ...

Read more
  • 09/09/2025
  • General, Software

In previous blog posts, I have introduced two essential components of a simple and universally applicable software architecture: events with dispatchers, listeners, and data pools. These already allow for many simple use cases ...

Read more
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Strictly Necessary Cookies

Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.