<div dir="ltr"><div><div>Hi all,<br><br></div>I'm trying to create a dynamic QChart plot based on QPieSeries. In this context I want to be able to detect which pie slice was clicked.and to do so I have set up a basic example (shown below).<br><br></div><div>My problem is that I am unable to detect which slice was clicked; when connecting the `clicked` signal of a Series I get a TypeError exception stating:<br><div style="margin-left:40px"><span style="font-family:monospace,monospace">TypeError: C++ type 'QPieSlice*' is not supported as a signal argument type</span><br></div></div><div>I'm guessing the feature is not yet implemented? I have unsuccessfully tried to connect each slice's `<span style="font-family:monospace,monospace">clicked</span>` signal to the slot, but I'm always getting the latest value in the series (
<span style="font-family:monospace,monospace">slice_clicked</span>
always sees <span style="font-family:monospace,monospace">i=1</span> always in the example below).<br><br></div><div>I'm getting the same exception when trying to connect the <span style="font-family:monospace,monospace">hovered</span> signal. I have also tried passing the type name as a string by using the <span style="font-family:monospace,monospace">@pyqtSlot</span> decorator, to no success.<br><br></div><div>Is there anything I can do to be able to connect the `clicked` signal for the QPieSeries?<br><br></div><div>I'm using Python 3.6.3 as bundled with Anaconda, Qt5.10.0, PyQt 5.10 and PyQtChart 5.10 as downloaded from pip on Windows 7 64 bits.<br></div><div><br></div><div>Sample code:<br><div style="margin-left:40px"><span style="font-family:monospace,monospace">import sys</span><br><span style="font-family:monospace,monospace">from PyQt5 import QtWidgets, QtChart, QtGui</span><br><span style="font-family:monospace,monospace"></span><br><span style="font-family:monospace,monospace">def slice_clicked(*args, **kwargs):</span><br><span style="font-family:monospace,monospace"> print('Slice clicked!')</span><br><span style="font-family:monospace,monospace"> print(args)</span><br><span style="font-family:monospace,monospace"> print(kwargs)</span><br><span style="font-family:monospace,monospace"></span><br><span style="font-family:monospace,monospace"># Create the PyQt app and main window</span><br><span style="font-family:monospace,monospace">app = QtWidgets.QApplication(sys.argv)</span><br><span style="font-family:monospace,monospace">window = QtWidgets.QMainWindow()</span><br><span style="font-family:monospace,monospace"># Create the QChart object and set a few options</span><br><span style="font-family:monospace,monospace">chart = QtChart.QChart()</span><br><span style="font-family:monospace,monospace">chart.legend().hide()</span><br><span style="font-family:monospace,monospace">chart.setAnimationOptions(QtChart.QChart.SeriesAnimations)</span><br><span style="font-family:monospace,monospace">chart.setTitle('My precious')</span><br><span style="font-family:monospace,monospace"># Create the series with the plot data with some silly data in it.</span><br><span style="font-family:monospace,monospace">series = QtChart.QPieSeries()</span><br><span style="font-family:monospace,monospace">series.setUseOpenGL(enable=True)</span><br><span style="font-family:monospace,monospace">series.append('Gandalf', 3)</span><br><span style="font-family:monospace,monospace">series.append('Frodo', 1)</span><br><span style="font-family:monospace,monospace"># Show the labels in each of the slices</span><br><span style="font-family:monospace,monospace">for i, slice in enumerate(series.slices()):</span><br><span style="font-family:monospace,monospace"> slice.setLabelVisible()</span><br><span style="font-family:monospace,monospace"> # The following does not work either (i is always `1`)</span><br><span style="font-family:monospace,monospace"> slice.clicked.connect(lambda: slice_clicked(i))</span><br><span style="font-family:monospace,monospace"># Connect the slice clicked signal to the slot</span><br><span style="font-family:monospace,monospace"># The following crashes with the following message:</span><br><span style="font-family:monospace,monospace"># Traceback (most recent call last):</span><br><span style="font-family:monospace,monospace"># File "C:/Users/jechevarria/.PyCharm2017.3/config/scratches/scratch_5.py", line 24, in <module></span><br><span style="font-family:monospace,monospace"># series.clicked.connect(slice_clicked)</span><br><span style="font-family:monospace,monospace"># <u><b>TypeError: C++ type 'QPieSlice*' is not supported as a signal argument type</b></u></span><br><span style="font-family:monospace,monospace"># series.clicked.connect(slice_clicked)</span><br><span style="font-family:monospace,monospace"># Add the series to the chart, create the view and add some more options</span><br><span style="font-family:monospace,monospace">chart.addSeries(series)</span><br><span style="font-family:monospace,monospace">view = QtChart.QChartView(chart)</span><br><span style="font-family:monospace,monospace">view.setRenderHint(QtGui.QPainter.Antialiasing)</span><br><span style="font-family:monospace,monospace"></span><br><span style="font-family:monospace,monospace">window.resize(640, 480)</span><br><span style="font-family:monospace,monospace">window.setCentralWidget(view)</span><br><span style="font-family:monospace,monospace">window.show()</span><br><span style="font-family:monospace,monospace"></span><br><span style="font-family:monospace,monospace">sys.exit(app.exec_())</span><br></div><div style="margin-left:40px"><span style="font-family:monospace,monospace"></span></div><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:arial,helvetica,sans-serif">Thanks in advance,<br></span></div><div><span style="font-family:arial,helvetica,sans-serif">Joseba</span><span style="font-family:monospace,monospace"><br></span></div></div>