Best way for draw points and lines?
My application allows the user to enter x and y coordinates using a table. Beside this, I have to draw these points and join them by lines. I know there are libraries like qwt that allow you to do this kind of things but for what I want, which is very simple, I would like to know if there is any other quick way to do it.
A Former User last edited by
Hi! Create a new class that inherits from QWidget. Override its inherited paintEvent method. Inside that method you can use QPainter to draw your points and lines. For details see the good old Analog Clock Window Example.
For ultra simple function, you can also draw on pixmap and show in label :)
// for loop draing lines...
Thanks for your reply.
But how would you do the following? You have the coordinates (0,0) in the top left corner of the widget and yo want to draw a point in the center. If you consider that the bottom right is the (10,10) coordinate, you want to draw the point in the (5,5). How do you establish that the bottom right corner is (10,10) in coordinate system if the widget has other dimensions?
I hope I have explained
Im not sure what u are asking.
If you have a widget or pixmap, its height() widdth() is the extend.
Do you mean that your area might be smaller than the pixmap or widget?
I'm a bit obtuse anyway hehe. I want to do something similar to what qwt graphs do, ie, for example, even if the plot has dimensions of 500x400, the x-axis goes from -10 to 10 and I paint the points according to these coordinates
Hehe obtuse can be cured with coffee often :)
If you want a virtual coordinate system u will have to transform the painter
Why not use QCustomplot ?
unlike qwt its super easy to get going.
Just add the 2 file to project and off u go.
Then grab sample and tweak it a bit and be happy.
it will be faster if u want virtual coordinates and u get zoom etc for free :)
I think scaling would be a possible solution. I had tried it but I had found the problem that the pen changed size and therefore had discarded. Then I found the QPen :: setCosmetic (bool cosmetic) function and I saw that I could fix the problem.