pyqtgraph - 背景颜色仅在重新加载后加载
pyqtgraph - Background color loads only after reloading
我知道我 在 pyqtgraph 中没有背景颜色问题 - 我正在编写一个 QGIS 软件插件,它有一个带有图形的附加对话框。我正在尝试设置背景颜色,只有在我使用 QGIS Plugin Reloader 插件重新加载插件后它才会加载(这个插件是为开发插件的人制作的,所以在代码发生任何变化后,你刷新并拥有一个新的加载到QGIS中。它不被普通用户使用)。
我的代码如下:
import pyqtgraph
...
def prepareGraph(self): # loads on button click
self.graphTitle = 'Graph one'
# prepare data - simplified, but data display correctly
self.y = something
self.x = something_else
self.buildGraph()
def buildGraph(self):
""" Add data to the graph """
pyqtgraph.setConfigOption('background', (230,230,230))
pyqtgraph.setConfigOption('foreground', (100,100,100))
dataColor = (102,178,255)
dataBorderColor = (180,220,255)
barGraph = self.graph.graphicsView
barGraph.clear()
barGraph.addItem(pyqtgraph.BarGraphItem(x=range(len(self.x)), height=self.y, width=0.5, brush=dataColor, pen=dataBorderColor))
barGraph.addItem(pyqtgraph.GridItem())
barGraph.getAxis('bottom').setTicks([self.x])
barGraph.setTitle(title=self.graphTitle)
self.showGraph()
def showGraph(self):
self.graph.show()
有趣的是 buildGraph()
的所有部分都可以毫无问题地加载,(即使是前景色!) 只有背景色不会。
这是一个已知错误还是设置前景色和背景色之间存在差异?链接的问题没有帮助我解决这个问题。
pyqtgraph==0.9.10
PyQt4==4.11.4
Python 2.7.3
pyqtgraph documentation 说到 setConfigOption
设置,即:
Note that this must be set before creating any widgets
在我的代码中我有
def buildGraph(self):
pyqtgraph.setConfigOption('background', (230,230,230))
pyqtgraph.setConfigOption('foreground', (100,100,100))
barGraph = self.graph.graphicsView
这就是我认为的 "before" 地方,但它是创建一个对象,而不是小部件。应该把setConfigOption
写在一个class里面,它负责存储pyqtgraph
对象。在我的例子中,它是在一个单独的文件中创建一个单独的对话框的 __init__
函数:
从 PyQt4 导入 QtGui、QtCore
从 plugin4_plot_widget 导入 Ui_Dialog
来自 plugin4_dialog 导入 plugin4Dialog
导入 pyqtgraph
class Graph(QtGui.QDialog, Ui_Dialog):
def __init__(self):
super(Graph, self).__init__()
pyqtgraph.setConfigOption('background', (230,230,230))
pyqtgraph.setConfigOption('foreground', (100,100,100))
self.setupUi(self)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
main = Graph()
main.show()
sys.exit(app.exec_())
我知道我
我的代码如下:
import pyqtgraph
...
def prepareGraph(self): # loads on button click
self.graphTitle = 'Graph one'
# prepare data - simplified, but data display correctly
self.y = something
self.x = something_else
self.buildGraph()
def buildGraph(self):
""" Add data to the graph """
pyqtgraph.setConfigOption('background', (230,230,230))
pyqtgraph.setConfigOption('foreground', (100,100,100))
dataColor = (102,178,255)
dataBorderColor = (180,220,255)
barGraph = self.graph.graphicsView
barGraph.clear()
barGraph.addItem(pyqtgraph.BarGraphItem(x=range(len(self.x)), height=self.y, width=0.5, brush=dataColor, pen=dataBorderColor))
barGraph.addItem(pyqtgraph.GridItem())
barGraph.getAxis('bottom').setTicks([self.x])
barGraph.setTitle(title=self.graphTitle)
self.showGraph()
def showGraph(self):
self.graph.show()
有趣的是 buildGraph()
的所有部分都可以毫无问题地加载,(即使是前景色!) 只有背景色不会。
这是一个已知错误还是设置前景色和背景色之间存在差异?链接的问题没有帮助我解决这个问题。
pyqtgraph==0.9.10
PyQt4==4.11.4
Python 2.7.3
pyqtgraph documentation 说到 setConfigOption
设置,即:
Note that this must be set before creating any widgets
在我的代码中我有
def buildGraph(self):
pyqtgraph.setConfigOption('background', (230,230,230))
pyqtgraph.setConfigOption('foreground', (100,100,100))
barGraph = self.graph.graphicsView
这就是我认为的 "before" 地方,但它是创建一个对象,而不是小部件。应该把setConfigOption
写在一个class里面,它负责存储pyqtgraph
对象。在我的例子中,它是在一个单独的文件中创建一个单独的对话框的 __init__
函数:
从 PyQt4 导入 QtGui、QtCore 从 plugin4_plot_widget 导入 Ui_Dialog 来自 plugin4_dialog 导入 plugin4Dialog 导入 pyqtgraph
class Graph(QtGui.QDialog, Ui_Dialog):
def __init__(self):
super(Graph, self).__init__()
pyqtgraph.setConfigOption('background', (230,230,230))
pyqtgraph.setConfigOption('foreground', (100,100,100))
self.setupUi(self)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
main = Graph()
main.show()
sys.exit(app.exec_())