Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why does my QGraphicsSimpleTextItem not display any plot information when I move my mouse?
Forum Updated to NodeBB v4.3 + New Features

Why does my QGraphicsSimpleTextItem not display any plot information when I move my mouse?

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E engsml

    @mrjj It is a QWidget. Does that make a difference?

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @engsml
    Nope, that's perfect. Normally it wont send mouseMove to QWidgets as far as i recall
    and you need to set mouseTracking to true to have them come without mouse buttons being pressed.

    E 1 Reply Last reply
    0
    • mrjjM mrjj

      @engsml
      Nope, that's perfect. Normally it wont send mouseMove to QWidgets as far as i recall
      and you need to set mouseTracking to true to have them come without mouse buttons being pressed.

      E Offline
      E Offline
      engsml
      wrote on last edited by
      #5

      @mrjj Yeah, the mouseMoveEvent works on everything but the actual QChart. I can only get the x and y points to display when I left click and drag it into the chart area. Otherwise it won't work. Would I have to include this function: QChartView::mouseMoveEvent(event) for it to work?

      mrjjM 1 Reply Last reply
      0
      • E engsml

        @mrjj Yeah, the mouseMoveEvent works on everything but the actual QChart. I can only get the x and y points to display when I left click and drag it into the chart area. Otherwise it won't work. Would I have to include this function: QChartView::mouseMoveEvent(event) for it to work?

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @engsml
        hi
        Its only sent to the widget under the mouse cursor.
        So yes, if you want to trap them there, you need to subclass and override that.
        However, if you need mouse info a global scope , maybe look into event filters.
        That allows to capture it across various Widgets without subclassing.
        If you already subclassed QChartView, override is ofcourse most easy.

        http://doc.qt.io/qt-5/eventsandfilters.html

        E 1 Reply Last reply
        0
        • mrjjM mrjj

          @engsml
          hi
          Its only sent to the widget under the mouse cursor.
          So yes, if you want to trap them there, you need to subclass and override that.
          However, if you need mouse info a global scope , maybe look into event filters.
          That allows to capture it across various Widgets without subclassing.
          If you already subclassed QChartView, override is ofcourse most easy.

          http://doc.qt.io/qt-5/eventsandfilters.html

          E Offline
          E Offline
          engsml
          wrote on last edited by
          #7

          @mrjj How would I subclass QChartView? I think that is what I am missing.

          mrjjM 1 Reply Last reply
          0
          • E engsml

            @mrjj How would I subclass QChartView? I think that is what I am missing.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #8

            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
            ...
             }
            
            E 1 Reply Last reply
            1
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #9

              updated code. paste error.
              explicit QChartView (QWidget* parent = 0) : QChartView(parent) {}
              --->
              explicit MyQChartView (QWidget* parent = 0) : QChartView(parent) {}

              1 Reply Last reply
              0
              • mrjjM mrjj

                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
                ...
                 }
                
                E Offline
                E Offline
                engsml
                wrote on last edited by
                #10

                @mrjj Thank you! Do I create another .cpp and header file and include this in my project?

                mrjjM 1 Reply Last reply
                0
                • E engsml

                  @mrjj Thank you! Do I create another .cpp and header file and include this in my project?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #11

                  @engsml
                  Yes, that is the cleanest. (IMHO)
                  and then just promote it. ( it sounds complex but really easy after first time)

                  E 2 Replies Last reply
                  1
                  • mrjjM mrjj

                    @engsml
                    Yes, that is the cleanest. (IMHO)
                    and then just promote it. ( it sounds complex but really easy after first time)

                    E Offline
                    E Offline
                    engsml
                    wrote on last edited by
                    #12

                    @mrjj Thank you! I will try that

                    1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @engsml
                      Yes, that is the cleanest. (IMHO)
                      and then just promote it. ( it sounds complex but really easy after first time)

                      E Offline
                      E Offline
                      engsml
                      wrote on last edited by
                      #13

                      @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?

                      mrjjM 1 Reply Last reply
                      0
                      • E engsml

                        @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?

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #14

                        @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.

                        E 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @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.

                          E Offline
                          E Offline
                          engsml
                          wrote on last edited by
                          #15

                          @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.

                          1 Reply Last reply
                          0
                          • mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by mrjj
                            #16

                            Hi
                            ah, QChartView is basically a QAbstractScrollArea which means it has the

                            https://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().

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved