PDA

View Full Version : QML extension - painting issue



kornicameister
3rd October 2011, 00:00
Hi again,

I am looking for a simple way to draw several rectangles (the amount depends on user). This could be quite simple, but I would like to have all these rectangles placed on the circle with specific radius. Apart from that each rectangle will contain text, and may contain icon image.

My main concern, as I've never done things like this, is to how
- draw the rectangle with text and icon inside of it
- how to put all these rectangles on the circle.

I think I should at first draw transparent circle which would be parent for all rectangles, therefore rectangles should be parents for text and icon inside of them, am I right ?

wysota
3rd October 2011, 10:05
- draw the rectangle with text and icon inside of it
Create a Rectangle Element with two children -- one for the icon and one for the text and anchor them to the parent.


- how to put all these rectangles on the circle.
That's quite simple. Write javascript code that will calculate x and y positions for different angles of the circle. Then instantiate your rectangles dynamically and place them in the calculated coordinates.The math involves calculating position of a point on a sloped line with distance equal to the radius of the circle (there is a right triangle there so it boils down to using sine or cosine).

kornicameister
3rd October 2011, 10:21
I wanted to make it in C++ code, but it seems that making it in QML code would be more flexible because these rectangles could be placed on any shape I would like to place them. Nevertheless the approach will be the same, even I want to implement such feature in C++.

wysota
3rd October 2011, 10:43
You can do the same thing in C++. I had the impression you wanted to do that in QML :)

kornicameister
3rd October 2011, 13:13
Now, after you've mentioned that, I am pretty confused where I would like to put it...

but I think that would be simpler do draw single Rectangle and than already in QML code attach to any shape I want to.
Basically I have a class which uses QDeclarativeListProperty and I am constantly thinking whether I should put all drawing inside this class which uses QDeclarativeListProperty or rather to the type T which is placed in QDeclarativeListProperty.

kornicameister
5th October 2011, 08:39
please remove this post
I decided to moved it's content to new thread