Skip to content

Commit e182081

Browse files
Merge pull request #26 from nlsfi/pyqt6-support
Add official PyQt6 support
2 parents 9f7e120 + e36af60 commit e182081

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
![GitHub release](https://img.shields.io/github/last-commit/philipstarkey/qtutils.svg)
55
[![Python Version](https://img.shields.io/pypi/pyversions/qtutils.svg)](https://python.org)
66
[![Documentation Status](https://readthedocs.org/projects/qtutils/badge/?version=stable)](https://qtutils.readthedocs.io/en/stable/?badge=stable)
7-
[![PyPi Version](https://img.shields.io/pypi/v/qtutils.svg)](https://pypi.python.org/pypi/qtutils/)
7+
[![PyPi Version](https://img.shields.io/pypi/v/qtutils.svg)](https://pypi.python.org/pypi/qtutils/)
88
[![Conda Version](https://img.shields.io/conda/v/labscript-suite/qtutils)](https://anaconda.org/labscript-suite/qtutils)
9-
[![PyPi License](https://img.shields.io/pypi/l/qtutils.svg)](https://github.com/philipstarkey/qtutils/blob/master/LICENSE.txt)
9+
[![PyPi License](https://img.shields.io/pypi/l/qtutils.svg)](https://github.com/philipstarkey/qtutils/blob/master/LICENSE.txt)
1010

1111
Utilities for providing concurrent access to Qt objects, simplified QSettings storage,
1212
and dynamic widget promotion when loading UI files, in Python Qt applications. Includes
@@ -30,7 +30,7 @@ license](https://ubuntu.com/legal/font-licence)).
3030
## Summary
3131

3232
`qtutils` is a Python library that provides some convenient features to Python
33-
applications using the PyQt5/PySide6 widget library.
33+
applications using the PyQt5/PyQt6/PySide6 widget library.
3434

3535
`qtutils` 4.0 dropped support for PySide2. If you need to use PySide2, you may use
3636
`qtutils` 3.1.0 or earlier.
@@ -53,8 +53,8 @@ applications using the PyQt5/PySide6 widget library.
5353
If you can't or don't want to provide attribution, please purchase a royalty-free
5454
license from http://p.yusukekamiyamane.com/
5555

56-
* `Qt`: a PyQt5/PySide6 agnostic interface to Qt that allows you to import qtutils.qt
57-
instead of PySide6 or PyQt5, and have your code run on both, with some convenience
56+
* `Qt`: a PyQt5/PyQt6/PySide6 agnostic interface to Qt that allows you to import qtutils.qt
57+
instead of PySide6 or PyQt5/6, and have your code run on both, with some convenience
5858
aliases to make it easier to write code that works with both libraries. Note that this
5959
is not a comprehensive abstraction layer like [QtPy](https://pypi.org/project/QtPy/)
6060
and your code will still need to be written in a way generally compatible with both

qtutils/UiLoader.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ def load(self, uifile, toplevel_instance=None):
8585

8686
else:
8787
from types import ModuleType
88-
from PyQt5 import uic
88+
try:
89+
from PyQt5 import uic
90+
except ImportError:
91+
from PyQt6 import uic
92+
8993

9094
class UiLoader(object):
9195
def __init__(self):

qtutils/qt.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
PYSIDE6 = 'PySide6'
2222
PYQT5 = 'PyQt5'
23+
PYQT6 = 'PyQt6'
2324
QT_ENV = None
2425

25-
libs = [PYQT5, PYSIDE6]
26+
libs = [PYQT5, PYSIDE6, PYQT6]
2627
for lib in libs:
2728
if lib in sys.modules:
2829
QT_ENV = lib
@@ -41,6 +42,8 @@
4142

4243
if QT_ENV == PYQT5:
4344
from PyQt5 import QtGui, QtCore, QtWidgets
45+
elif QT_ENV == PYQT6:
46+
from PyQt6 import QtGui, QtCore, QtWidgets
4447
elif QT_ENV == PYSIDE6:
4548
from PySide6 import QtGui, QtCore, QtWidgets
4649

@@ -49,13 +52,13 @@
4952
sys.modules['qtutils.qt.QtCore'] = QtCore
5053

5154
# Make Signal available under both names 'Signal' and 'pyqtSignal':
52-
if QT_ENV == PYQT5:
55+
if QT_ENV in (PYQT5, PYQT6):
5356
QtCore.Signal = QtCore.pyqtSignal
5457
else:
5558
QtCore.pyqtSignal = QtCore.Signal
5659

5760
# Make some names that moved from QtWidgets to QtGui available in both modules:
58-
if QT_ENV == PYQT5:
61+
if QT_ENV == PYQT5:
5962
QtGui.QAction = QtWidgets.QAction
6063
QtGui.QShortcut = QtWidgets.QShortcut
6164
else:

0 commit comments

Comments
 (0)