Tracking cursor C++
I'm currently working on a class that will create an x,y graph according to given parameters when called, but I also want a description of each point in the x,y graph when the cursor hovers over it.
For example, if I generate a graph displaying market growth(year, amount, rate), and I hover over a certain point, I want a little box to appear and in it will be details about that point like the year, stocks, stock prices, position in graph, etc. I already finished the graph generator, but now I need help with this part.
How do I achieve this in C++?
Note -- I'm using Ubuntu.
Another note --- I created my graph without graphical libraries, and without any graphical functions. If you didn't understand my question at first, I'm basically asking 2 things: 1. How do I implement cursor tracking to my non-graphical graph with outer graphical libraries, and 2. if 开发者_开发技巧not possible, which library should I use to create a graph and how do I use them for cursor tracking?
Sorry for the confusion, it's just the first time I'm using graphics. I'm more of a "no external libraries" programmer.
Thanks.
I would opt for Qt since there is 3rd party library called Qwt based on Qt which provides quite a lot of technical widgets including plotting ones (you might also be interested in Qwt dedicated sub-forum on qtcentre).
The solution for "txt-box on hover" effect is in fact very simple, you just have to set tooltip via QWidget::setToolTip( const QString& ) for the node widgets.
You need to maintain a list of objects in the graph, and then do a "hit test" for each coordinate the cursor hovers over. This hit test basically entails iterating through your list seeing if the current coordinates fall on the object on the graph for that element.
If you're creating a graph via the console, I don't believe there is anyway for that console to know where your mouse is. A lot of the graphical functions you'd find in a language like Java just don't exist in C++, since the creators of C++ wanted these graphical libraries to be powerful, rather than portable. I second the recommendation for QT, though I've never used it personally. It's the library I've seen most recommended elsewhere.
精彩评论