繁体   English   中英

如何展现Qpie的所有传奇?

[英]How to show all the legend of Qpie?

如何展现Qpie的所有传奇? 话会变成....

我应该如何解决这个问题? 程序画面

self.slice = self.series.slices()[1]
self.slice.setExploded()
self.slice.setLabelVisible()
self.slice.setPen(QPen(Qt.darkGreen, 2))
self.slice.setBrush(Qt.green)
#self.slice.setLabelBrush(labelBrush)
self.slice.setLabelFont(pieFont)

self.chart = QChart()
self.chart.addSeries(self.series)
self.chart.setTitle('History Data')
self.chart.legend().hide()
self.chart.createDefaultAxes()
self.chart.setFont(titleFont)
self.chart.setTitleFont(titleFont)
#self.chart.setBackgroundBrush(bgG)
#self.chart.setTitleBrush(QBrush(Qt.white))

self.chart.setAnimationOptions(QChart.SeriesAnimations)
self.chart.legend().setVisible(True)
self.chart.legend().setAlignment(Qt.AlignBottom)
self._chart_view = QChartView(self.chart)
self._chart_view.setRenderHint(QPainter.Antialiasing)
self.charWidget.setChart(self.chart)

图例未显示,因为窗口宽度很小。

如果您增加屏幕宽度,则会出现字幕。

注意 setFixedSize()

import sys
from PyQt5 import QtChart
from PyQt5.QtChart import QChartView, QChart
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPainter, QFont
from PyQt5.QtWidgets import QApplication, QMainWindow


class Window(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("PyQtChart Pie Chart")
        
        # without problem
        self.setFixedSize(500, 300)

        # with problem
        self.setFixedSize(400, 300)

        self.create_piechart()
        self.show()

    def create_piechart(self):
        # serie
        series = QtChart.QPieSeries()
        series.append("l011111111111", 80)
        series.append("l02", 70)
        series.append("l03", 50)
        series.append("l04", 40)
        series.append("l05", 30)
        series.append("l06", 80)
        series.append("l07", 70)
        series.append("l08", 50)
        series.append("l09", 40)
        series.append("l10", 30)


        #chart
        titleFont = QFont('Times', 28)
        chart = QChart()
        chart.addSeries(series)
        chart.createDefaultAxes()
        chart.setAnimationOptions(QChart.SeriesAnimations)
        chart.setTitle('History Data')
        chart.legend().hide()
        chart.setFont(titleFont)
        chart.setTitleFont(titleFont)
        chart.legend().setVisible(True)
        chart.legend().setAlignment(Qt.AlignBottom)
        
        chartview = QChartView(chart)
        chartview.setRenderHint(QPainter.Antialiasing)
        #chartview.setChart(chart)
        self.setCentralWidget(chartview)


if __name__ == '__main__':
    App = QApplication(sys.argv)
    window = Window()
    sys.exit(App.exec_())

希望这可以帮助。

暂无
暂无

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

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