0

Create a circle with mouse event and get back data of points in a file

My question is, how to create a circle in this way: on my interface, I have a button, and a QGraphicsView with a picture on it, when I click on the button, I would like to have a point which is the center of the picture to appear and when I move the mouse a line representing the radius is visible too and varying when I move the mouse. When I click with the left button of the mouse, it creates the circle and I get back a vector of points of this circle that I store in a datafile where I define in the code the number of points (a value that the user can't choose with the interface).

My question about this is, is it possible to do this? I had some pre-works on visual studio to plot a contour (when I click on the left button it creates point and the second time a line between the two points) but there was a problem at the end about a file i needed that make me change my works with a circle but it seems more complicated with Qt to realize it.

Thank you in advance for your reading and for your reponse.

  • Try a look at [example1](http://stackoverflow.com/a/11218063/1329652) and [example2](http://stackoverflow.com/a/11235761/1329652). They show how to react to a click only. You'd need to be stateful and react to a button press and then to a button release. It should be easy to generate points for a circle once you know the circle's bounding rectangle. – Kuba hasn't forgotten Monica Jul 16 '15 at 18:42
  • Thank you a lot, I will have a look at the both example! I'll let you know if I succeed in doing what I want. – alexandreMepage Jul 17 '15 at 14:33
  • Hello, I was looking at your two examples, the first one I've got no problems to see what it is doing, but for the second example, I've some trouble: I have created these headers: Circle.h, View.h, Notifier.h and NotifyingItem.h and these cpp files: view.cpp and main.cpp. My problem is coming from this line "Notifier notifier;" in the view.h with the following error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int and this one: C2146: syntax error : missing ';' before identifier 'notifier'. I've tried to look at how I can resolve it but haven't find a way. – alexandreMepage Jul 20 '15 at 13:20
  • You're asking a question about code without showing the code. Most likely, the `Notifier` type is not declared. Perhaps you spelled it wrong, or didn't include the interface file that declares it. – Kuba hasn't forgotten Monica Jul 20 '15 at 13:56
  • My bad, I had a misdeclaration of the different includes, whereas I was sure I've been carefull with it. – alexandreMepage Jul 20 '15 at 15:04
  • So, do you still have the problem? If so, post the code. Otherwise, I'm voting to close as it can't be reproduced anymore and is a typo. In any case, **posting questions about code without showing the code makes them immediately off-topic**. There is usually no way to answer such questions, and even if sometimes we can deduce what's wrong, it's still too much extra effort, and the questions are useless to others. Remember that a question that is only useful to you is nominally *off-topic on a public site viewed by millions*. – Kuba hasn't forgotten Monica Jul 20 '15 at 15:08

0 Answers0