Unsolved Why does my QGraphicsSimpleTextItem not display any plot information when I move my mouse?
-
@mrjj How would I subclass QChartView? I think that is what I am missing.
-
hi
class MyQChartView : public QChartView { Q_OBJECT public: explicit MyQChartView (QWidget* parent = 0) : QChartView(parent) {} ~QChartView() {} protected: virtual void moveEvent(QMoveEvent* event) override { ..... } };
If you have the QChartView in UI file, you can use promotion to easy replace it at runtime with your version.
http://doc.qt.io/qt-5/designer-using-custom-widgets.html
just give it MyQChartView as class name and MyQChartView .h (if you put it in own file)
else what ever .h file it lives in.update: you might want to call base class version as it might use it.
virtual void moveEvent(QMoveEvent* event) override { QChartView::moveEvent(event); // call base first ... }
-
updated code. paste error.
explicit QChartView (QWidget* parent = 0) : QChartView(parent) {}
--->
explicit MyQChartView (QWidget* parent = 0) : QChartView(parent) {} -
@mrjj Thank you! Do I create another .cpp and header file and include this in my project?
-
@engsml
Yes, that is the cleanest. (IMHO)
and then just promote it. ( it sounds complex but really easy after first time) -
@mrjj Thank you! I will try that
-
@mrjj When I create the new class, what do I make the base class? Also, what does promoting accomplish in the sense that it overrides the QChartView class?
-
@engsml
just see code snippet ?
Like that. its complete override. with mousemove.promotion is just easy way to get your type into the UI file.
Creator just note the actual type you want and at runtime, its your new widget instead.
Like a runtime replace.
if you insert the Chart via code, you have no use for promotion. -
@mrjj Hi. thanks for your help! I ended up not being able to figure it out, but am currently looking into the event filters option. I added QtCharts::QChartView::mouseMoveEvent(event); to my function to pass the event to the chartView but it still won't display any information when the mouse is on the plot. Any ideas? I'm following the "callout" example which has a similar structure.
-
Hi
ah, QChartView is basically a QAbstractScrollArea which means it has thehttps://doc.qt.io/qt-5/qabstractscrollarea.html#viewport
There is a high chance that this viewport objects uses/eats the mouseMove and hence the Widget dont see them
or viewport have no mouse tracking.i might be able to test it tonight.
Else event filter sounds like a plan. set it on viewport().