<div dir="ltr">I cannot test here because I have not QChart installed, so I can't answer on the series.clicked problem.<div>About the slice.clicked connect, the reason you are receiving always the same number is because you are using lambda within a for cycle, which simply uses the latest value for "i" as an argument for the function: lambda will act as any other function, if it cannot find "i" in its scope, will look for it in locals() or eventually globals().</div><div><br></div><div>To get that working you have to explicitly declare the argument:</div><div>slice.clicked.connect(lambda i=i: slice_clicked(i))</div><div><br></div><div>Be careful when using lambdas with signals, since they can have optional arguments (such as QAbstractButton's clicked) and you have to take them into account when adding lambda arguments.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-03-21 12:45 GMT+01:00 Joseba Echevarria García <span dir="ltr"><<a href="mailto:josebagar@gmail.com" target="_blank">josebagar@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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.<wbr>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(<wbr>QtChart.QChart.<wbr>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=<wbr>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/.<wbr>PyCharm2017.3/config/<wbr>scratches/scratch_5.py", line 24, in <module></span><br><span style="font-family:monospace,monospace">#         series.clicked.connect(slice_<wbr>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_<wbr>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.<wbr>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>
<br>______________________________<wbr>_________________<br>
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" target="_blank">https://www.<wbr>riverbankcomputing.com/<wbr>mailman/listinfo/pyqt</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>
</div>