简体   繁体   中英

Importing QtGui from pyqtgraph.Qt as *

I am trying to insert a graph in my PySide GUI using pyqtgraph .

Objective: keep using wildcard imports for PySide while obeying pyqtgraph s import rules.

Apparently, PySide.QtCore and PySide.QtGui needs to be imported through pyqtgraph for the package to work properly. In the example, its written like this:

from pyqtgraph.Qt import QtCore, QtGui

Typically I import the PySide components as:

from PySide.QtCore import *
from PySide.QtGui  import *

Notice the wildcard import statement. The problem is that the following throws an exception on import ( ImportError: No module named QtGui ):

from pyqtgraph.Qt.QtCore import *
from pyqtgraph.Qt.QtGui  import *

Is there a way around this? I would prefer not to have to go back into my code and replaces all the self.clock_timer = QTimer() with self.clock_timer = QtCore.Timer() statements.

Short Cut: If I could avoid going through pyqtgraph to import QtCore and QtGui , that would be even better. When I try to use do it (using the first import style) certain features (eg AutoPan) don't work.

Put this at the beginning of your application to ensure that pyqtgraph pre-loads the pyside modules (and does whatever monkey-patching it needs to do):

import os

os.environ['PYQTGRAPH_QT_LIB'] = 'PySide'

from pyqtgraph import Qt

Now you can safely use your preferred imports, because sys.modules will already contain whatever (patched) modules pyqtgraph loaded:

from PySide.QtCore import *

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM