qtpy
qtpy copied to clipboard
Allow to specify Qt version via an environment variable (`QT_VERSION`)
In some circumstances it may be useful to specify the Qt version qtpy should use without without specifying which implementation to use. Currently it is only possible leave it up to qtpy to decide or to exactly specify the API using the QT_API environment variable.
In my particular use case I would need this feature in an application using QtPdf (which is only available in Qt6) but am indifferent whether PyQt6 or PySide6 should be used. I am aware that it is possible to set QT_API=pyqt6 and pyqt will fall back to PySide6 when PyQt6 is not available but I would consider this a bit unsatisfactory since it will trigger a warning for an unproblematic case, the actual intention does not become clear when looking at the code and it does not work when only Qt5 should be used instead.
This feature could be realized by allowing to set QT_API to a Qt version , e.g. QT_API=Qt6 or by allowing to set QT_API to a list of values, e.g. QT_API=pyqt6,pyside6.
Hey @Bzero, thanks for reporting. I think it'd better to create a new env var for this case because QT_API is used by other packages (e.g. Matplotlib and Qtconsole, if I'm not mistaken). So, we could have QT_VERSION=qt6, which is similar to what you suggested.
@dalthviz, what do you think?
Thanks for your reply. I was not aware that QT_API is used by other packages too so I agree that adding a QT_VERSION environment variable makes sense.
The only drawback I see with this is that QT_API and QT_VERSION may be in conflict with each other, I suppose in that case qtpy should probably just ignore QT_VERSION and trigger a warning.
I can prepare a PR to implement this feature.
The only drawback I see with this is that QT_API and QT_VERSION may be in conflict with each other, I suppose in that case qtpy should probably just ignore QT_VERSION and trigger a warning.
Agreed. QT_API should have precedence over QT_VERSION and we should report a warning about it. Also, another warning should be shown if the QT_VERSION value can't be set because there are no matching bindings.
I can prepare a PR to implement this feature.
That'd be great, thanks!
Just in case, creating a QT_VERSION env var makes sense :+1: Thank you @Bzero for bringing this up and your willingness to implement it!