View Full Version : Right Mouseclick on QAreaSeries - no response

6th March 2019, 09:21
Hi there,

What I did:


#include <QMouseEvent>

class myQAreaSeries : public QAreaSeries{


virtual void mousePressEvent(QMouseEvent *);



#include "myqareaseries.h"


void myQAreaSeries::mousePressEvent(QMouseEvent *event){
qDebug() << "button is pressed";

No reaction.

What am I doing wrong here?

1 Do I somehow have to activate mousetracking?
2 Do I have have to call "mousePressEvent(..)" somehow. And if...how?

This is my first "from the scratch" inplementation of mouseclicks. Up to now I always could use some predefined Signal (i.e. rightClicked()). There is a "clicked()" signal on QAreaSeries, but reacts only on leftclick. I could also use the "pressed()" signal. But I'd like to learn the "proper" way.

Thanks in advance, Lars

6th March 2019, 22:16
QAreaSeries inherits from QAbstractSeries which inherits from QObject (not QWidget). QObject does not implement any virtual UI events since it does not represent something you can interact with on screen. The clicked() signal you see for QAreaSeries is something that is generated inside the QGraphicsView that contains the QChart item. Note that QChart also inherits from QObject, not QWidget, so it doesn't have any UI events you can grab either. The only place where you can see a UI event is in the QGraphicsView itself.

Note that none of the classes in the entire Qt Chart framework have any virtual functions, so there is no way you can derive from any of them to change or override their behavior.

7th March 2019, 09:33
Hey d-stranz,

as always good to hearing from you. That doesn't exactely sound encouraging. I was about to switch back to qwt (after we both discussed QChart some time before). Unfortunately I didn't. Thanks anyway for the enlightenement. Any suggestions?

best, Lars

7th March 2019, 22:35
QChart is probably the worst library in all of Qt. Totally inflexible - if you don't like what it does out of the box, too bad, because you can't change it.

I'm sold on QCustomPlot. It is very well designed, easy to use, and can be extended to suit. For example, I needed to make scatter plots where each point could be a different symbol shape, size, and color, and highlight status. To do this in QChart would require a separate QScatterSeries for every combination, as many as one QScatterSeries for each point. In QCustomPlot, I created a new plot series type that would do this using one instance of the series, with vectors of properties in addition to the x-y coordinates. Not only that, but I created a special kind of "data source" (based on QAbstractItemModel) that could drive creating the series based on a model.

So if you are not locked into QChart, check out QCustomPlot. You could probably do the same with Qwt, but I stopped using it when Qwt6 was introduced. There were enough major changes between Qwt5 and Qwt6 that it would force me to redo most of my graphics. So, if I have to port, I might as well look at all of the options, and I considered QChart, Qwt6, and QCustomPlot. I liked QCustomPlot best, and I am gradually porting everything over.

27th March 2019, 11:59
Hey d_stranz,

short wrap up: Finally I used the hovered() signal of QAreaSeries to beforehand request the data needed later on to form the customContextMenu. Not very straight forward.

Thanks anyway.

Cheers, Lars