<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#ffffff" text="#2e3436" link="#2a76c6" vlink="#2e3436">
<div>Joseba,</div>
<div><br>
</div>
<div>You beat me to it!</div>
<div><br>
</div>
<div>I still think your original problem is a bug which you might consider submitting. Not sure how though!</div>
<div><br>
</div>
<div>Regards,</div>
<div>Tony.</div>
<div><br>
</div>
<div>On Wed, 2018-03-21 at 16:17 +0100, Joseba Echevarria García wrote:</div>
<blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex">
<div dir="auto">Good evening again,
<div dir="auto"><br>
</div>
<div dir="auto">Connecting the `clicked` event for each QPieSeries to a slot and getting the originating QPieSlice with self.sender() inside the slot seems to be working fine.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Thank you all for your suggestions! </div>
<div dir="auto"><br>
</div>
<div dir="auto">Joseba</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">El 21 mar. 2018 16:05, "Joseba Echevarria García" <<a href="mailto:josebagar@gmail.com">josebagar@gmail.com</a>> escribió:<br type="attribution">
<blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex">
<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" target="_blank">
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
<div class="quoted-text"><br>
from PyQt5 import QtWidgets, QtChart, QtGui<br>
<br>
</div>
@pyqtSlot(QtChart.QPieSlice)<br>
def series_clicked(clicked_slice):<br>
    print('Slice clicked!')<br>
    print(clicked_slice.pieSize)
<div class="quoted-text"><br>
<br>
# Create the PyQt app and main window<br>
app = QtWidgets.QApplication(sys.<wbr>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(<wbr>QtChart.QChart.<wbr>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>
</div>
series.setObjectName('series')
<div class="quoted-text"><br>
series.setUseOpenGL(enable=<wbr>True)<br>
series.append('Gandalf', 3)<br>
series.append('Frodo', 1)<br>
# Show the labels in each of the slices<br>
</div>
for i, pie_slice in enumerate(series.slices()):<br>
    pie_slice.setLabelVisible()
<div class="quoted-text"><br>
# Connect the slice clicked signal to the slot<br>
</div>
<div class="quoted-text">#     Traceback (most recent call last):<br>
</div>
#       File "C:/Users/jechevarria/.<wbr>PyCharm2017.3/config/<wbr>scratches/scratch_5.py", line 32, in <module><br>
#         series.clicked.connect(series_<wbr>clicked)<br>
#     TypeError: C++ type 'QPieSlice*' is not supported as a signal argument type<br>
series.clicked.connect(series_<wbr>clicked)
<div class="quoted-text"><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.<wbr>QPainter.Antialiasing)<br>
<br>
window.resize(640, 480)<br>
window.setCentralWidget(view)<br>
window.show()<br>
<br>
</div>
# 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="elided-text">
<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 type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex">
Joseba,<br>
<span><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="m_6648852864079724793HOEnZb"><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>
</div>
</blockquote>
</div>
<br>
</div>
<pre>_______________________________________________
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a>
<a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></pre>
</blockquote>
<div><span>
<pre>-- <br></pre>
<div>
<div><font size="2"><font color="#3366ff"><b>Tony Arnold</b> MBCS, CITP | Senior IT Security Analyst | Directorate of IT Services | G64, Kilburn Building | The University of Manchester | Manchester M13 9PL |
</font><font color="#ff0000">T:</font><font color="#3366ff"> +44 161 275 6093 | </font>
<font color="#ff0000">M:</font><font color="#3366ff"> +44 773 330 0039</font></font></div>
</div>
</span></div>
</body>
</html>