Light Markers and Points Selection Example#

The Light Markers and Points Selection example shows how to use light markers and point selections in a series.

QChart with Light Markers shown

Creating the chart and its elements#

We start by creating a series, filling it with the data, and enabling the light marker and point selection features. It is important not to set points visibility to True, because light markers functionality is an independent feature and setting both would result in undesired behavior.

Then we create the QChart, the QChartview and the control widget with its layout to arrange customization elements.

Creating UI for configuring the chart#

The next step is where we create user interface elements that allow customizing the chart, including setting light marker and selection marker images.

We create the label for the marker selection combobox and fill the combobox with the items. We then provide functionality to the combobox, allowing the user’s selection to set the desired light marker image. As light markers are enabled and disabled by setting a valid QImage or setting an empty QImage(), we need to make sure that if the user does not wish unselected points to be displayed, we do not actually set the light marker image. If checking isn’t performed, a new QImage will be set as the light marker and unselected points will be visible even though it has been switched off.

Almost the same procedure applies to the selected point light marker and line color. The only difference is that there is no need to check the visibility of unselected points as it doesn’t affect the functionality.

A small difference comes with changing visibility of unselected points. As it was mentioned before, making light markers invisible is achieved by setting the light marker to an empty QImage(). That is why, depending on checkbox state, selected point light marker is set to an empty QImage or to the light marker extracted from the current index of the corresponding combobox.

The final part is to lay out the widgets within the main widget and set the main window size.


To use this example, change any of the comboboxes and checkboxes controlling the markers, line color, and unselected point visibility on the right. Then try clicking on points in the chart to select or deselect them.

Download this example