单击时更改QCandlestickSet中“蜡烛”的颜色

时间:2020-01-28 05:38:47

标签: python pyqt pyqt5

我正在尝试更改QCandlestickSet对象的颜色,但是它不显示任何颜色。我已经成功地更改了QCandlestickSet对象中“灯芯”的颜色和宽度,但是在单击图表中的烛台后,“蜡烛体”部分没有任何颜色。

下面是python程序的引用。

import sys
from PyQt5 import QtCore, QtGui, QtWidgets, QtChart
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtChart import *

class Window(QMainWindow):

    def __init__(self):
        super().__init__()

        self.data = ((20190111,15.28,15.54,15.22,15.26),(20190114,15.3,15.56,15.3,15.42),(20190115,15.7,15.98,15.4,15.4),(20190116,15.58,15.6,15.24,15.34))
        self.chart = QChart()
        self.series = QCandlestickSeries(clicked=self.onCandleClicked)

        color = QColor()
        color.setRgb(229,57, 53)
        self.series.setDecreasingColor(color)

        color.setRgb(76,175, 80)
        self.series.setIncreasingColor(color)

        self.series.setBodyOutlineVisible(False)

        self.date_labels = []
        self.resize(640, 480)

        for num, o, h, l, c in self.data:
            self.series.append(QCandlestickSet(o, h, l, c))
            self.date_labels.append(str(num))

        self.chart.addSeries(self.series)

        self.chart.createDefaultAxes()
        self.chart.legend().hide()
        self.chart.axisX(self.series).setCategories(self.date_labels)

        self.chartview = QChartView(self.chart)
        self.chartview.setChart(self.chart)

        central_widget = QtWidgets.QWidget()        
        lay = QtWidgets.QVBoxLayout(central_widget)
        lay.addWidget(self.chartview)
        self.setCentralWidget(central_widget)

        self.show()

    def onCandleClicked(self, value):
        candleSet = value
        color = QColor()
        pen = QPen()
        brush = QBrush()


        color.setRgb(0,140,140)
        pen.setColor(color)
        pen.setWidth(3)        
        candleSet.setPen(pen)

        brush.setColor(color) #I want to change the color of candle        
        candleSet.setBrush(brush)


app = QApplication(sys.argv)
window = Window()
sys.exit(app.exec_())

程序输出

点击一些烛台后程序的输出

0 个答案:

没有答案