Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PyQt5.QtChart - How to change QPieSeries color?
Forum Updated to NodeBB v4.3 + New Features

PyQt5.QtChart - How to change QPieSeries color?

Scheduled Pinned Locked Moved Solved Qt for Python
2 Posts 2 Posters 661 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PatitotectiveP Offline
    PatitotectiveP Offline
    Patitotective
    wrote on last edited by Patitotective
    #1

    I'm trying to create a pie chart using QPieSeries from PyQtChart but when i run the program i get this:
    Screenshot from 2021-08-19 16-17-38.png
    Where the colors are very similar, so my question is if there is a way to change this chart colors? to make them more different.


    The code:

    # Libraries
    import sys
    
    # PyQt5
    from PyQt5.QtWidgets import *
    from PyQt5.QtGui import QCursor, QPainter, QPalette, QColor
    
    from PyQt5.QtChart import *
    
    class MainWindow(QMainWindow):
        def __init__(self, parent=None):
            super().__init__(parent)
            
            self.setCentralWidget(self.create_pie_chart())
    
        def create_pie_chart(self):
            series = QPieSeries()
    
            series.append("C++", 80)
            series.append("C#", 95)
            series.append("C", 61)
            series.append("Python", 150)
            series.append("Java", 82)
            series.append("JavaScript", 90)
            series.append("Shell", 70)
    
            chart = QChart()
            chart.addSeries(series)
            chart.setAnimationOptions(QChart.SeriesAnimations)
            chart.setTitle("Programming languages")
    
            chart_view = QChartView(chart)
            chart_view.setRenderHint(QPainter.Antialiasing)
    
            return chart_view
    
    app = QApplication(sys.argv)
    
    mainwindow = MainWindow()
    mainwindow.show()
    sys.exit(app.exec_())
    
    JonBJ 1 Reply Last reply
    0
    • PatitotectiveP Patitotective

      I'm trying to create a pie chart using QPieSeries from PyQtChart but when i run the program i get this:
      Screenshot from 2021-08-19 16-17-38.png
      Where the colors are very similar, so my question is if there is a way to change this chart colors? to make them more different.


      The code:

      # Libraries
      import sys
      
      # PyQt5
      from PyQt5.QtWidgets import *
      from PyQt5.QtGui import QCursor, QPainter, QPalette, QColor
      
      from PyQt5.QtChart import *
      
      class MainWindow(QMainWindow):
          def __init__(self, parent=None):
              super().__init__(parent)
              
              self.setCentralWidget(self.create_pie_chart())
      
          def create_pie_chart(self):
              series = QPieSeries()
      
              series.append("C++", 80)
              series.append("C#", 95)
              series.append("C", 61)
              series.append("Python", 150)
              series.append("Java", 82)
              series.append("JavaScript", 90)
              series.append("Shell", 70)
      
              chart = QChart()
              chart.addSeries(series)
              chart.setAnimationOptions(QChart.SeriesAnimations)
              chart.setTitle("Programming languages")
      
              chart_view = QChartView(chart)
              chart_view.setRenderHint(QPainter.Antialiasing)
      
              return chart_view
      
      app = QApplication(sys.argv)
      
      mainwindow = MainWindow()
      mainwindow.show()
      sys.exit(app.exec_())
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Patitotective
      https://doc.qt.io/qt-5/qpieslice.html#color-prop
      Example code: https://stackoverflow.com/questions/56727499/attach-colors-of-my-choosing-to-each-slice-of-qpieseries

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved