This is a model-view-controller (MVC) project template built around Qt for Python.
The goal is to create a design pattern which leverages Qt Creator while spending as little time as possible with Qt itself.
Working build scripts, built around pyinstaller
, are included as well.
This project should theoretically work with a broad range of environments.
- Python 3
- packages listed in
requirements.txt
This project was developed and tested with the following, more specific versions:
- Python 3.8.1
- packages listed in
requirements.txt.lock
MainWindow
can be opened in Qt Creator and edited graphically via the included qtcreator.pro
project file.
More information on Qt Creator can be found here:
Getting Started | Qt Creator Manual
The corresponding python source code is automatically updated in scripts/build
, but it can be updated without building via scripts/update_ui
The Qt StyleSheet located at src/widgets/stylesheet.css
gets loaded into MainWindow at runtime.
The practical effect of this is that the current styles are not reflected in the project in Qt Creator. As a work-around, to see them in Qt Creator, copy-paste the contents of the file into the widget property directly.
There are bash scripts located in the scripts
dir. They should be simple enough that, even if you are in windows, you can use them as a guide to performing the task at hand.
I use pyenv
and pyenv-virtualenv
to achieve RVM-named-gemset-inspired virtual environments for my projects.
scripts/uninstall
and scripts/reinstall
require that you are using pyenv
, pyenv-virtualenv
, and that your .python-version
file follows this syntax:
<python-version>@<environment-name>
For example, this is how I configured my system:
pyenv install 3.8.1
pyenv virtualenv 3.8.1 3.8.1@qt_python_project
pyenv local 3.8.1@qt_python_project
For more information on pyenv
, see:
pyenv/pyenv: Simple Python version management
If you are not using pyenv
(which does not work on Windows) you can safely ignore the uninstall, reinstall scripts.
This project template, as a way of example, provides a GUI for querying an instrument ID string.
Most of the work in the application is done in Controller.handle_button_click()
, located at src/controller.py
. This is a good place to start to see all the pieces (Model, View and Controller) coming together.