From d108ca8b43bfb78da38b039c958a969a9a55cfc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20McMullan?= Date: Sun, 11 Nov 2018 19:33:02 +0000 Subject: [PATCH] basic PySide2 support in examples/qt.py #438 --- examples/qt.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/examples/qt.py b/examples/qt.py index d0ed3300..50226d50 100644 --- a/examples/qt.py +++ b/examples/qt.py @@ -22,6 +22,7 @@ PYQT4 = False PYQT5 = False PYSIDE = False +PYSIDE2 = False if "pyqt4" in sys.argv: PYQT4 = True @@ -37,7 +38,7 @@ from PyQt5.QtCore import * # noinspection PyUnresolvedReferences from PyQt5.QtWidgets import * -elif "pyside" in sys.argv: +elif "pyside" in sys.argv and not 'pyside2' in sys.argv: PYSIDE = True # noinspection PyUnresolvedReferences import PySide @@ -47,6 +48,18 @@ from PySide.QtGui import * # noinspection PyUnresolvedReferences from PySide.QtCore import * +elif "pyside2" in sys.argv: + PYSIDE2 = True + # noinspection PyUnresolvedReferences + import PySide2 + # noinspection PyUnresolvedReferences + from PySide2 import QtCore + # noinspection PyUnresolvedReferences + from PySide2.QtGui import * + # noinspection PyUnresolvedReferences + from PySide2.QtCore import * + # noinspection PyUnresolvedReferences + from PySide2.QtWidgets import * else: print("USAGE:") print(" qt.py pyqt4") @@ -107,6 +120,9 @@ def check_versions(): elif PYSIDE: print("[qt.py] PySide {v1} (qt {v2})".format( v1=PySide.__version__, v2=QtCore.__version__)) + elif PYSIDE2: + print("[qt.py] PySide2 {v1} (qt {v2})".format( + v1=PySide2.__version__, v2=QtCore.__version__)) # CEF Python version requirement assert cef.__version__ >= "55.4", "CEF Python v55.4+ required to run this" @@ -126,6 +142,8 @@ def __init__(self): self.setWindowTitle("PyQt5 example") elif PYSIDE: self.setWindowTitle("PySide example") + elif PYSIDE2: + self.setWindowTitle("PySide2 example") self.setFocusPolicy(Qt.StrongFocus) self.setupLayout() @@ -147,7 +165,7 @@ def setupLayout(self): frame.setLayout(layout) self.setCentralWidget(frame) - if PYQT5 and WINDOWS: + if (PYSIDE2 or PYQT5) and WINDOWS: # On Windows with PyQt5 main window must be shown first # before CEF browser is embedded, otherwise window is # not resized and application hangs during resize. @@ -156,7 +174,7 @@ def setupLayout(self): # Browser can be embedded only after layout was set up self.cef_widget.embedBrowser() - if PYQT5 and LINUX: + if (PYSIDE2 or PYQT5) and LINUX: # On Linux with PyQt5 the QX11EmbedContainer widget is # no more available. An equivalent in Qt5 is to create # a hidden window, embed CEF browser in it and then @@ -204,7 +222,7 @@ def focusOutEvent(self, event): self.browser.SetFocus(False) def embedBrowser(self): - if PYQT5 and LINUX: + if (PYSIDE2 or PYQT5) and LINUX: # noinspection PyUnresolvedReferences self.hidden_window = QWindow() window_info = cef.WindowInfo()