Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. QCustomplot: Coords by Mouseclick
Forum Updated to NodeBB v4.3 + New Features

QCustomplot: Coords by Mouseclick

Scheduled Pinned Locked Moved 3rd Party Software
6 Posts 2 Posters 12.4k 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.
  • R Offline
    R Offline
    rotpar
    wrote on last edited by
    #1

    Hi everybody,

    I'm new to Qt and I'm using QCustomPlot to create a plot out of some informations. Now I want to click with the left mousebutton into the graph and want to get the coordinates of the position I clicked at. I couldn't find any solution for it yet, but I can't believe I'm the only one who wants to do this :). It seems like I'm missing something obvious. Can someone give me a hint?

    Thanks,
    rotpar

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You can either overload the mouse related events or use one of the "mouse signals":http://www.workslikeclockwork.com/other/qcustomplot-doc/classQCustomPlot.html#aca75bf9afb5dd19349c375de2a87a051 from QCustomplot

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rotpar
        wrote on last edited by
        #3

        Hi,

        just to complete this for the next newbie who trips over this little stone. I hoped there's a simpler way to do this but I solved the problem as follows:

        somewhere in the widgets .cpp file:
        @connect(plot_, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(clickedGraph()));@
        ^^thanks for the hint with the mouseEvents

        in the .h file of course:
        @public slots:
        void clickedGraph()@

        and clickedGraph() does:
        @void FVolumePlayerWidget::clickedGraph()
        {
        QPoint p = this->mapFromGlobal(QCursor::pos()); //get mouse position
        QRect plotPos = plot_->axisRect(); //get origin of axis
        int x = p.x() - 44; //calc coordinate at clicked position
        //TODO: get Position of stuff to calc the value 44

        //Mark selected position
        QCPItemLine *arrow = new QCPItemLine(plot_);
        plot_->addItem(arrow);
        arrow->start->setCoords(x, 99);
        arrow->end->setCoords(x, ecgValueArray[x]); //ecgValues is th y-data I build the graph with earlier
        arrow->setHead(QCPLineEnding::esSpikeArrow);
        }@

        so this works out for me so far for fixed graph sizes and because of the amount of data I'm plotting... but maybe it helps someone somehow.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You don't need the call to QCursor::pos() nor to map if you use the QMouseEvent that is send by the signal.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rotpar
            wrote on last edited by
            #5

            okay thanks,

            I will remind that for later...gotta get forward. If I remember this post after optimizing my program I will post an update.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @
              connect(plot_, SIGNAL(mousePress(QMouseEvent*)), SLOT(clickedGraph(QMouseEvent*)));

              void FVolumePlayerWidget::clickedGraph(QMouseEvent *event)
              {
              QPoint p = event->pos();
              //etc...
              }
              @

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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