Results 1 to 6 of 6

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

  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.

  3. #3
    Join Date
    Jan 2017
    Posts
    54
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

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

    I'll swap the gridLayout for a QHBoxLayout and give it a try. Thanks

    Upon second thought, I had thought a QHboxLayout was a drag and drop layout I could add via the Qt Designer, but its not. How do I add it to my UI?
    Last edited by dennisvz; 12th January 2020 at 01:19.

  4. #4
    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

    Upon second thought, I had thought a QHboxLayout was a drag and drop layout I could add via the Qt Designer
    Yes, of course it is, second item under Layouts:

    Designer.PNG

    You can also select everything in your widget, right-click in your top level widget and choose "Lay out horizontally" to wrap the contents in a horizontal layout.
    <=== 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.

  5. #5
    Join Date
    Jan 2017
    Posts
    54
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

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

    Sorry, I was looking specifically for a QHBoxLayout; I did not realize it was the same as just plain Horizontal Layout.

  6. #6
    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

    Qt Designer is intended for use by GUI designers, who may not be programmers. So if you look at all of the names for UI items in Qt Designer, I don't think any of them have the same names as the Qt C++ classes that implement them. Of course, as programmers who also design UIs, we have to learn both sets of names. :-(
    <=== 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, 10:29
  2. Qwt Side-bySide bar charts/graphs
    By bwnicewo in forum Qwt
    Replies: 7
    Last Post: 12th June 2012, 07:39
  3. Manifest / Side by Side configuration.
    By hickscorp in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2010, 06:22
  4. side-by-side configuration is incorrect
    By trueqt in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2009, 01:35
  5. Replies: 5
    Last Post: 15th February 2008, 03: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.