1
+ import os
2
+
3
+
4
+ USE_QT6 = False
5
+ USE_PYQT6 = False
6
+ USE_PYQT5 = False
7
+ USE_PYSIDE6 = False
8
+ QT_PACKAGE = ""
9
+
10
+ try :
11
+ raise ImportError
12
+ import PySide6 .QtCore as QtCore
13
+ import PySide6 .QtGui as QtGui
14
+ import PySide6 .QtWidgets as QtWidgets
15
+ USE_QT6 = True
16
+ USE_PYSIDE6 = True
17
+ QT_PACKAGE = "PySide6"
18
+ except (ImportError , ModuleNotFoundError ):
19
+ try :
20
+ import PyQt6 .QtCore as QtCore
21
+ import PyQt6 .QtWidgets as QtWidgets
22
+ import PyQt6 .QtGui as QtGui
23
+ USE_QT6 = True
24
+ USE_PYQT6 = True
25
+ QT_PACKAGE = "PyQt6"
26
+ except (ImportError , ModuleNotFoundError ):
27
+ import PyQt5 .QtCore as QtCore
28
+ import PyQt5 .QtWidgets as QtWidgets
29
+ import PyQt5 .QtGui as QtGui
30
+ USE_PYQT5 = True
31
+ QT_PACKAGE = "PyQt5"
32
+
33
+ import modules ._qt_ver as _qt_ver
34
+ _qt_ver .USE_QT6 = USE_QT6
35
+ _qt_ver .USE_PYQT6 = USE_PYQT6
36
+ _qt_ver .USE_PYQT5 = USE_PYQT5
37
+ _qt_ver .USE_PYSIDE6 = USE_PYSIDE6
38
+ _qt_ver .QT_PACKAGE = QT_PACKAGE
39
+ _qt_ver .QtCore = QtCore
40
+ _qt_ver .QtGui = QtGui
41
+
42
+ from modules ._qt_constants import *
43
+
44
+ # pyqtgraph will check/try to import PyQT6 on load and might fail if some packages were imported
45
+ # (if pyQt6 is halfway installed): so we force the version here
46
+ os .environ .setdefault ("PYQTGRAPH_QT_LIB" , qasync .QtModuleName )
47
+
48
+ # make sure pyqtgraph it imported from here so PYQTGRAPH_QT_LIB will always be set
49
+ import pyqtgraph as pg # noqa
50
+
51
+ # set default configuration
52
+ pg .setConfigOptions (antialias = True )
53
+ pg .setConfigOption ("background" , "w" )
54
+ pg .setConfigOption ("foreground" , "k" )
55
+
56
+ # QtWidgets
57
+ QT_EXPANDING = (
58
+ QtWidgets .QSizePolicy .Policy .Expanding
59
+ if USE_QT6
60
+ else QtWidgets .QSizePolicy .Expanding
61
+ )
62
+ QT_FIXED = (
63
+ QtWidgets .QSizePolicy .Policy .Fixed if USE_QT6 else QtWidgets .QSizePolicy .Fixed
64
+ )
65
+
66
+ # for textedit
67
+ QT_SCROLLBAR_ALWAYSOFF = (
68
+ QtCore .Qt .ScrollBarPolicy .ScrollBarAlwaysOff
69
+ if USE_QT6
70
+ else QtCore .Qt .ScrollBarAlwaysOff
71
+ )
72
+ QT_TEXTEDIT_NOWRAP = (
73
+ QtWidgets .QTextEdit .LineWrapMode .NoWrap if USE_QT6 else QtWidgets .QTextEdit .NoWrap
74
+ )
75
+
76
+ # for popup
77
+ QT_STACKINGMODE_STACKONE = (
78
+ QtWidgets .QStackedLayout .StackingMode .StackOne
79
+ if USE_QT6
80
+ else QtWidgets .QStackedLayout .StackOne
81
+ )
82
+ QT_STACKINGMODE_STACKALL = (
83
+ QtWidgets .QStackedLayout .StackingMode .StackAll
84
+ if USE_QT6
85
+ else QtWidgets .QStackedLayout .StackAll
86
+ )
87
+ QT_PE_WIDGET = (
88
+ QtWidgets .QStyle .PrimitiveElement .PE_Widget
89
+ if USE_QT6
90
+ else QtWidgets .QStyle .PE_Widget
91
+ )
92
+ QT_WA_TRANSLUCENT_BACKGROUND = (
93
+ QtCore .Qt .WidgetAttribute .WA_TranslucentBackground
94
+ if USE_QT6
95
+ else QtCore .Qt .WA_TranslucentBackground
96
+ )
97
+ QT_WA_TRANSPARENT_FOR_MOUSE_EVENTS = (
98
+ QtCore .Qt .WidgetAttribute .WA_TransparentForMouseEvents
99
+ if USE_QT6
100
+ else QtCore .Qt .WA_TransparentForMouseEvents
101
+ )
102
+
103
+ # for map widgets
104
+ QT_COMPOSITION_MODE_SOURCEIN = (
105
+ QtGui .QPainter .CompositionMode .CompositionMode_SourceIn
106
+ if USE_QT6
107
+ else QtGui .QPainter .CompositionMode_SourceIn
108
+ )
109
+ QT_COMPOSITION_MODE_DARKEN = (
110
+ QtGui .QPainter .CompositionMode .CompositionMode_Darken
111
+ if USE_QT6
112
+ else QtGui .QPainter .CompositionMode_Darken
113
+ )
0 commit comments