Results 1 to 6 of 6

Thread: Place two pie charts side by side on one gridLayout

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2017
    Posts
    54
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Place two pie charts side by side on one gridLayout

    Using QChart and QChartView I show a single pie chart on a Ui with a gridLayout built in Qt Creator/Designer. I would now like to show two piecharts on the same grid layout -- side by side - with each chart taking up half the grid (vertically speaking) -- essentially making two big, equal-sized columns.
    I use this code to show the first pie:
    Qt Code:
    1. series = QPieSeries()
    2. chart = QChart()
    3. # the pie chart is made here
    4. self.chartView = QChartView(chart)
    5. self.ui.gridLayout.addWidget(self.chartView)
    To copy to clipboard, switch view to plain text mode 
    and have duplicate code (with different pie data) below it for the second pie.
    The resulting charts show one on top of the other stretching across the UI, and the top pie takes up 3/4 of vertical space and the other gets 1/4 of the vertical space.

    I have played around with various combinations of positioning, like:
    Qt Code:
    1. self.ui.gridLayout.addWidget(self.chartView, 0, 1)
    To copy to clipboard, switch view to plain text mode 

    but nothing works. Is there a way to get what I want without redesigning the UI with two grid layouts?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Place two pie charts side by side on one gridLayout

    According to the QGridLayout docs, there is no addWidget() method that takes only a single argument. So, PyQt must be defaulting these arguments to something, but I don't know what. You should at least provide 0, 0 as the second two arguments.

    You can't add the same chartView instance to a layout more than once. So the instances in cell 0, 0 and 0, 1 must be different.

    Unless you also plan to put other things in this layout, why don't you just use a QHBoxLayout instead? Then you simply call addWidget() without the need for row or column numbers.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 30th January 2015, 09:29
  2. Qwt Side-bySide bar charts/graphs
    By bwnicewo in forum Qwt
    Replies: 7
    Last Post: 12th June 2012, 06:39
  3. Manifest / Side by Side configuration.
    By hickscorp in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2010, 05:22
  4. side-by-side configuration is incorrect
    By trueqt in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2009, 00:35
  5. Replies: 5
    Last Post: 15th February 2008, 02:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.