[PyQt] Cannot connect to the clicked signal of a QPieSeries
Joseba Echevarria GarcĂa
josebagar at gmail.com
Wed Mar 21 11:45:36 GMT 2018
Hi all,
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).
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:
TypeError: C++ type 'QPieSlice*' is not supported as a signal argument type
I'm guessing the feature is not yet implemented? I have unsuccessfully
tried to connect each slice's `clicked` signal to the slot, but I'm always
getting the latest value in the series ( slice_clicked always sees i=1
always in the example below).
I'm getting the same exception when trying to connect the hovered signal. I
have also tried passing the type name as a string by using the @pyqtSlot
decorator, to no success.
Is there anything I can do to be able to connect the `clicked` signal for
the QPieSeries?
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.
Sample code:
import sys
from PyQt5 import QtWidgets, QtChart, QtGui
def slice_clicked(*args, **kwargs):
print('Slice clicked!')
print(args)
print(kwargs)
# Create the PyQt app and main window
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QMainWindow()
# Create the QChart object and set a few options
chart = QtChart.QChart()
chart.legend().hide()
chart.setAnimationOptions(QtChart.QChart.SeriesAnimations)
chart.setTitle('My precious')
# Create the series with the plot data with some silly data in it.
series = QtChart.QPieSeries()
series.setUseOpenGL(enable=True)
series.append('Gandalf', 3)
series.append('Frodo', 1)
# Show the labels in each of the slices
for i, slice in enumerate(series.slices()):
slice.setLabelVisible()
# The following does not work either (i is always `1`)
slice.clicked.connect(lambda: slice_clicked(i))
# Connect the slice clicked signal to the slot
# The following crashes with the following message:
# Traceback (most recent call last):
# File
"C:/Users/jechevarria/.PyCharm2017.3/config/scratches/scratch_5.py", line
24, in <module>
# series.clicked.connect(slice_clicked)
# *TypeError: C++ type 'QPieSlice*' is not supported as a signal
argument type*
# series.clicked.connect(slice_clicked)
# Add the series to the chart, create the view and add some more options
chart.addSeries(series)
view = QtChart.QChartView(chart)
view.setRenderHint(QtGui.QPainter.Antialiasing)
window.resize(640, 480)
window.setCentralWidget(view)
window.show()
sys.exit(app.exec_())
Thanks in advance,
Joseba
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180321/c6745f7c/attachment.html>
More information about the PyQt
mailing list