Results 1 to 5 of 5

Thread: Right Mouseclick on QAreaSeries - no response

  1. #1
    Join Date
    May 2015
    Posts
    42
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Right Mouseclick on QAreaSeries - no response

    Hi there,

    What I did:

    Qt Code:
    1. #ifndef MYQAREASERIES_H
    2. #define MYQAREASERIES_H
    3.  
    4. #include <QMouseEvent>
    5.  
    6. class myQAreaSeries : public QAreaSeries{
    7.  
    8. Q_OBJECT
    9.  
    10. protected:
    11. virtual void mousePressEvent(QMouseEvent *);
    12.  
    13. public:
    14. myQAreaSeries();
    15. ~myQAreaSeries();
    16.  
    17. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "myqareaseries.h"
    2.  
    3. myQAreaSeries::myQAreaSeries(){
    4. ...
    5. }
    6.  
    7. void myQAreaSeries::mousePressEvent(QMouseEvent *event){
    8. qDebug() << "button is pressed";
    9. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by mustermann.klaus@gmx.de; 6th March 2019 at 09:29. Reason: subscribed to notification

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Right Mouseclick on QAreaSeries - no response

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    May 2015
    Posts
    42
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Right Mouseclick on QAreaSeries - no response

    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

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Right Mouseclick on QAreaSeries - no response

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    May 2015
    Posts
    42
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Right Mouseclick on QAreaSeries - no response

    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

  6. The following user says thank you to mustermann.klaus@gmx.de for this useful post:

    d_stranz (27th March 2019)

Similar Threads

  1. Mouseclick outside from widget
    By binio in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2013, 06:53
  2. Selecting next line with mouseclick
    By Jake123 in forum Newbie
    Replies: 1
    Last Post: 4th February 2013, 07:21
  3. Getting sender for mouseclick with QwtPlot
    By lxman in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2011, 02:43
  4. how to get MouseClick Event in this case
    By yxmaomao in forum Qt Programming
    Replies: 3
    Last Post: 17th July 2008, 04:03
  5. select QGraphicsItems by mouseclick
    By Shawn in forum Qt Programming
    Replies: 20
    Last Post: 31st July 2007, 14:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.