Skip to main content

PyQt6 UI templates resource converter

Project description

pyqt6rc

GitHub_repo

Script to convert resource paths generated by QT6 designer.
PyQt6 does not provide pyrcc6 script to convert resources.
In current PyQt6 implementation, files created by pyuic6 scripts using Qt resources has wrong path.
This script is converting .ui files into .py files and using importlib to fix resource path.

There are multiple solutions to this problem:

  • One is to use QtCore.QDir.addSearchPath().
    But still path generated by designer does not follow pattern "prefix:path".
  • Use of importlib_resources, which is third party library.
  • Native python3.7+ solution using importlib, which is adopted by this script.

Conversion

Generated template by pyuic6:

icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/icons/icon1.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)

Generated template by pyqt6rc script:

icon = QtGui.QIcon()
with path("myPackage.resources.icons", "icon1.png") as f_path:
    icon.addPixmap(QtGui.QPixmap(str(f_path)), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)

Usage examples

Package structure example

myPackage
│   __init__.py    
│
└───resources
|   |   __init__.py
│   │   image1.png
│   │   image2.png
│   │   resources.qrc
|   |   ...
|   |
|   └───icons
│       │   __init__.py
│       │   icon1.png
│       │   icon2.png
│       │   ...
│   
└───templates
    │   template1.ui
    │   template2.ui

Convert all .ui files located in templates directory

pyqt6rc /myPackage/resources/resources.qrc -p myPackage.resources -i /myPackage/templates

Convert template1.ui

pyqt6rc /myPackage/resources/resources.qrc -p myPackage.resources -i /myPackage/templates/template1.ui

Convert template1.ui and save it in /tmp directory

pyqt6rc /myPackage/resources/resources.qrc -p myPackage.resources -i /myPackage/templates/template1.ui -o /tmp

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqt6rc-0.1.1.tar.gz (9.3 kB view hashes)

Uploaded Source

Built Distribution

pyqt6rc-0.1.1-py3-none-any.whl (14.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page