<div dir="ltr"><div><div><div><div><div>Good evening to all,<br><br></div>Thank you very much for your quick responses!<br></div>I have not been able to make your suggestion work, Tony. I believe I have adapted your suggestion but connecting the signal still raises TypeError (in fact, even doing `print(series.clicked)` raises the TypeError).<br><br></div>I have been able to make Maurizio's suggestion work, although I'd rather go with a more elegant solution if possible.<br><br></div><div>Looking at the development snapshot changelogs of <a href="https://www.riverbankcomputing.com/static/Downloads/sip/ChangeLog-4.19.9.dev1803171438">sip</a> & PyQt I've seen some changes regarding PieSlices; maybe it's just unsupported as of now.<br></div><div>I'm trying to get the pie slice object with QObject.sender(); If that does not work I'll probably go with Maurizio's solution.<br></div><div><br>The code modified as per Tony's suggestion is shown below:<br><span style="font-family:monospace,monospace">import sys<br>from PyQt5.QtCore import pyqtSlot, QObject<br>from PyQt5 import QtWidgets, QtChart, QtGui<br><br>@pyqtSlot(QtChart.QPieSlice)<br>def series_clicked(clicked_slice):<br>    print('Slice clicked!')<br>    print(clicked_slice.pieSize)<br><br># Create the PyQt app and main window<br>app = QtWidgets.QApplication(sys.argv)<br>window = QtWidgets.QMainWindow()<br># Create the QChart object and set a few options<br>chart = QtChart.QChart()<br>chart.legend().hide()<br>chart.setAnimationOptions(QtChart.QChart.SeriesAnimations)<br>chart.setTitle('My precious')<br># Create the series with the plot data with some silly data in it.<br>series = QtChart.QPieSeries()<br>series.setObjectName('series')<br>series.setUseOpenGL(enable=True)<br>series.append('Gandalf', 3)<br>series.append('Frodo', 1)<br># Show the labels in each of the slices<br>for i, pie_slice in enumerate(series.slices()):<br>    pie_slice.setLabelVisible()<br># Connect the slice clicked signal to the slot<br>#     Traceback (most recent call last):<br>#       File "C:/Users/jechevarria/.PyCharm2017.3/config/scratches/scratch_5.py", line 32, in <module><br>#         series.clicked.connect(series_clicked)<br>#     TypeError: C++ type 'QPieSlice*' is not supported as a signal argument type<br>series.clicked.connect(series_clicked)<br># Add the series to the chart, create the view and add some more options<br>chart.addSeries(series)<br>view = QtChart.QChartView(chart)<br>view.setRenderHint(QtGui.QPainter.Antialiasing)<br><br>window.resize(640, 480)<br>window.setCentralWidget(view)<br>window.show()<br><br># It's exec_ because exec is a reserved word in Python<br>sys.exit(app.exec_())</span><br><br></div>Regards,<br></div>Joseba<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 21, 2018 at 3:05 PM, Tony Arnold <span dir="ltr"><<a href="mailto:tony.arnold@manchester.ac.uk" target="_blank">tony.arnold@manchester.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Joseba,<br>
<span class=""><br>
On Wed, 2018-03-21 at 12:45 +0100, Joseba Echevarria García wrote:<br>
<br>
><br>
I'm trying to create a dynamic QChart plot based on QPieSeries. In<br>
> this context I want to be able to detect which pie slice was<br>
> clicked.and to do so I have set up a basic example (shown below).<br>
><br>
> My problem is that I am unable to detect which slice was clicked;<br>
> when connecting the `clicked` signal of a Series I get a TypeError<br>
> exception stating:<br>
> TypeError: C++ type 'QPieSlice*' is not supported as a signal<br>
> argument type<br>
><br>
> I'm guessing the feature is not yet implemented? I have<br>
> unsuccessfully tried to connect each slice's `clicked` signal to the<br>
> slot, but I'm always getting the latest value in the series (<br>
> slice_clicked  always sees i=1 always in the example below).<br>
><br>
> I'm getting the same exception when trying to connect the hovered<br>
> signal. I have also tried passing the type name as a string by using<br>
> the @pyqtSlot decorator, to no success.<br>
><br>
> Is there anything I can do to be able to connect the `clicked` signal<br>
> for the QPieSeries?<br>
><br>
> I'm using Python 3.6.3 as bundled with Anaconda, Qt5.10.0, PyQt 5.10<br>
> and PyQtChart 5.10 as downloaded from pip on Windows 7 64 bits.<br>
><br>
> Sample code:<br>
> import sys<br>
> from PyQt5 import QtWidgets, QtChart, QtGui<br>
<br>
</span>I would add a PyQtSlot decorator for this signal and specify the<br>
argument type, viz.,<br>
<br>
from PyQt5.QtChart import QPieSlice<br>
<br>
@pyqtSlot(QPieSlice)<br>
def slice_clicked(slice):<br>
    print('Slice clicked!')<br>
    print(slice.pieSize)<br>
<br>
Hope this helps.<br>
<br>
Regards,<br>
Tony.<br>
<span class="HOEnZb"><font color="#888888">--<br>
Tony Arnold MBCS, CITP | Senior IT Security Analyst | Directorate of IT Services | G64, Kilburn Building | The University of Manchester | Manchester M13 9PL | T: +44 161 275 6093 | M: +44 773 330 0039</font></span></blockquote></div><br></div>