Selected Point Configuration Example#

This example shows how to configure individual points of a QLineSeries.

Line chart with controls for configuring selected points

Features demonstrated#

In this application you will learn how to:

  • Select a series of points on click

  • Override the configuration for the following properties of specific points:

    • Color

    • Size

    • Label visibility

    • Text format of the label

Subclass QMainWindow#

Create a subclass of QMainWindow to contain the chart and controls.

Create a line series#

Create a QLineSeries containing the points to plot. Give it a name and make the points visible.

Create the point configuration controls#

Now, create controls to configure the color, size, and label visibility attributes of a point.

  1. Create an associated label for each control, so the user knows what the control does.

  2. For the color and size, use a QComboBox, populating it with a variety of colors and size choices.

  3. Create the final two controls. Create a QCheckbox to control the visibility of the selected point, and a QLineEdit to allow the user to provide a custom label for it.


Do not set initial values for any of the controls, as a point will always be selected showing its current settings.

Populate the controls upon selecting a point#

Add the logic to set the current control values depending on the chosen point. Note that the whole series value is used if there is no customization for a selected point. In this case, if the series is set to show blue points, a blue color value will be shown in the color combobox.

Perform some actions upon clicking on the lineseries. Look up the point clicked on and remove the prior point selection. Finally, select the point that was clicked on. This makes the point larger to indicate its selection. The current selected point’s index and PointConfigurations are saved to a member variable for later use.

Query the PointConfigurations, and use those to find the matching indices in the combo boxes. Set the current indices of the comboboxes to the corresponding values you looked up. Similarly, look up the values in PointConfigurations, and update the checkbox and line edit controls.

Provide the logic to configure the selected point#

Now that the controls are populated with some values, add logic to do something when the value changes. Connect the control signals and the logic, to configure the selected point based on the chosen values in the controls. You can do this by setting the QXYSeries::PointConfiguration value that is associated with the control, to the m_selectedPointConfig and PointConfigurations member variables, and call QXYSeries::setPointConfiguration.

Create the chart and lay out the controls#

Finally, create the chart and its view, add the series to the chart, create the layout of the window, and select an initial point.

In our entrypoint file, instantiate the ChartWindow, resize it, show it, and start the event loop.

You now have a fully functioning application that demonstrates how to customize individual chart points.


To use this example, click any point you’d like to customize, change any of the comboboxes and checkboxes controlling the individual point color, size, label visibility. You can customize the label text in the line edit at the bottom.

There are three special formatting strings for the label that you can use: @pointX, @pointY, and @index. These are replaced with the x value, y value, and index of the point, respectively. More information about that can be found in the documentation for QtCharts.QXYSeries.pointLabelsFormat.

Download this example