Skip to content

mrjohannchang/minimum-qt-for-python-desktop-application-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minimum Qt for Python Desktop Application Demo

screenshot

This is only for demonstrating and reference.

Usage

pdm run desktop-app

Installation

Install with pipx

pipx install git+https://github.com/mrjohannchang/minimum-qt-for-python-desktop-application-demo.git

Development

Design concepts

  1. Object-oriented programming
  2. Model–view–viewmodel (MVVM)

Environment

  1. Python 3.11+
  2. Qt for Python
  3. PDM
  4. Git

Setup

pdm install

Step by step reference

  1. Create an empty project with Git.

    git init
    
  2. Initialize the Python project with PDM.

    pdm init
    
  3. Add Qt for Python as a dependent library.

    pdm add PySide6
    
  4. Create a Main Window Qt Designer UI file with Qt Designer.

    mkdir src/minimum_qt_for_python_desktop_application_demo_desktop
    touch src/minimum_qt_for_python_desktop_application_demo_desktop/__init__.py
    mkdir src/minimum_qt_for_python_desktop_application_demo_desktop/ui
    touch src/minimum_qt_for_python_desktop_application_demo_desktop/ui/__init__.py
    pdm run pyside6-designer
    
  5. Create the desktop application entry point. If you chose PEP 582 – Python local packages directory for this project and plan to use PyCharm, at the time of writing, PyCharm does not support PEP 582 directly. Please manually set __pypackages__/<major.minor>/lib and src as Sources Root.

    1. After configuring the script file in pyproject.toml, we need to install it:

      pdm install
      
    2. Then we will be able to run it:

      pdm run desktop-app
      
  6. Add the logging function to the custom SDK.

  7. Use custom QMainWindow class to add the window exit hook.

    Note: This is undocumented but IMHO the most authenticated way to do it.

  8. Demonstrate how to hook the UI building

  9. Demonstrate how to get the component from the Qt Designer UI file

  10. Demonstrate the usage of model–view–viewmodel (MVVM).

License

Mozilla Public License Version 2.0

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages