简体   繁体   English

从 pyqtgraph.Qt 导入 QtGui 作为 *

[英]Importing QtGui from pyqtgraph.Qt as *

I am trying to insert a graph in my PySide GUI using pyqtgraph .我正在尝试使用pyqtgraph在我的 PySide GUI 中插入一个图形。

Objective: keep using wildcard imports for PySide while obeying pyqtgraph s import rules.目标:在遵守pyqtgraph的导入规则的同时,继续为 PySide 使用通配符导入。

Apparently, PySide.QtCore and PySide.QtGui needs to be imported through pyqtgraph for the package to work properly.显然, PySide.QtCorePySide.QtGui需要通过pyqtgraph导入pyqtgraph使包正常工作。 In the example, its written like this:在示例中,它是这样写的:

from pyqtgraph.Qt import QtCore, QtGui

Typically I import the PySide components as:通常我将 PySide 组件导入为:

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 ):问题是以下在导入时抛出异常( 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.我不想回到我的代码并用self.clock_timer = QtCore.Timer()语句替换所有self.clock_timer = QTimer() self.clock_timer = QtCore.Timer()语句。

Short Cut: If I could avoid going through pyqtgraph to import QtCore and QtGui , that would be even better.捷径:如果我能避免通过pyqtgraph导入QtCoreQtGui ,那就更好了。 When I try to use do it (using the first import style) certain features (eg AutoPan) don't work.当我尝试使用 do it(使用第一个导入样式)时,某些功能(例如 AutoPan)不起作用。

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):把它放在你的应用程序的开头,以确保 pyqtgraph 预加载 pyside 模块(并执行它需要做的任何猴子补丁):

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:现在你可以安全地使用你喜欢的导入,因为sys.modules已经包含了 pyqtgraph 加载的任何(修补)模块:

from PySide.QtCore import *

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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