Skip to content

Commit a9a30ae

Browse files
authored
Merge pull request cztomczak#490 from donalm/pyside2
basic PySide2 support in examples/qt.py cztomczak#438
2 parents ce21ff9 + cdf6c23 commit a9a30ae

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

examples/qt.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
PYQT4 = False
2323
PYQT5 = False
2424
PYSIDE = False
25+
PYSIDE2 = False
2526

2627
if "pyqt4" in sys.argv:
2728
PYQT4 = True
@@ -47,11 +48,24 @@
4748
from PySide.QtGui import *
4849
# noinspection PyUnresolvedReferences
4950
from PySide.QtCore import *
51+
elif "pyside2" in sys.argv:
52+
PYSIDE2 = True
53+
# noinspection PyUnresolvedReferences
54+
import PySide2
55+
# noinspection PyUnresolvedReferences
56+
from PySide2 import QtCore
57+
# noinspection PyUnresolvedReferences
58+
from PySide2.QtGui import *
59+
# noinspection PyUnresolvedReferences
60+
from PySide2.QtCore import *
61+
# noinspection PyUnresolvedReferences
62+
from PySide2.QtWidgets import *
5063
else:
5164
print("USAGE:")
5265
print(" qt.py pyqt4")
5366
print(" qt.py pyqt5")
5467
print(" qt.py pyside")
68+
print(" qt.py pyside2")
5569
sys.exit(1)
5670

5771
# Fix for PyCharm hints warnings when using static methods
@@ -107,6 +121,9 @@ def check_versions():
107121
elif PYSIDE:
108122
print("[qt.py] PySide {v1} (qt {v2})".format(
109123
v1=PySide.__version__, v2=QtCore.__version__))
124+
elif PYSIDE2:
125+
print("[qt.py] PySide2 {v1} (qt {v2})".format(
126+
v1=PySide2.__version__, v2=QtCore.__version__))
110127
# CEF Python version requirement
111128
assert cef.__version__ >= "55.4", "CEF Python v55.4+ required to run this"
112129

@@ -126,6 +143,8 @@ def __init__(self):
126143
self.setWindowTitle("PyQt5 example")
127144
elif PYSIDE:
128145
self.setWindowTitle("PySide example")
146+
elif PYSIDE2:
147+
self.setWindowTitle("PySide2 example")
129148
self.setFocusPolicy(Qt.StrongFocus)
130149
self.setupLayout()
131150

@@ -147,7 +166,7 @@ def setupLayout(self):
147166
frame.setLayout(layout)
148167
self.setCentralWidget(frame)
149168

150-
if PYQT5 and WINDOWS:
169+
if (PYSIDE2 or PYQT5) and WINDOWS:
151170
# On Windows with PyQt5 main window must be shown first
152171
# before CEF browser is embedded, otherwise window is
153172
# not resized and application hangs during resize.
@@ -156,7 +175,7 @@ def setupLayout(self):
156175
# Browser can be embedded only after layout was set up
157176
self.cef_widget.embedBrowser()
158177

159-
if PYQT5 and LINUX:
178+
if (PYSIDE2 or PYQT5) and LINUX:
160179
# On Linux with PyQt5 the QX11EmbedContainer widget is
161180
# no more available. An equivalent in Qt5 is to create
162181
# a hidden window, embed CEF browser in it and then
@@ -204,7 +223,7 @@ def focusOutEvent(self, event):
204223
self.browser.SetFocus(False)
205224

206225
def embedBrowser(self):
207-
if PYQT5 and LINUX:
226+
if (PYSIDE2 or PYQT5) and LINUX:
208227
# noinspection PyUnresolvedReferences
209228
self.hidden_window = QWindow()
210229
window_info = cef.WindowInfo()

0 commit comments

Comments
 (0)