PDA

View Full Version : Newbie: Circuits and GraphicsView



RY
10th September 2008, 02:37
Hello,

Part of a project that I have to do requires that I create a picture of an electric circuit that is editable. As in "circuit", I mean resistors, voltage sources, etc. As in "editable", I mean that I can right click on a component to delete it, insert a new one, edit its value, etc.

Does anyone know a good way to go about doing this?

Should I use the GraphicsView Framework to hold the circuit?

Should I use png or tiff as circuit elements (like resistors and stuff)? Or should I try to draw the parts with Qt?

I would really, really appreciate any help.

I'm trying to use the GraphicsView Framework right now. If this is a good route to go and you have any experience using GraphicsView Framework, your help would be much appreciated!

Thank you!

From NewbieRY.

aamer4yu
10th September 2008, 05:13
I guess you are on the right path for using Graphics View.
There have been threads related to such electric components in the forum, you can search for them.

Also have a look at the examples of Graphics View in Qt Demo

wysota
10th September 2008, 08:01
Yes, use GraphicsView. As for items themselves, it depends on you - you can use pixmaps but you can also draw those items yourself which would give you more flexibility (for example ability to change the colour of the item).

RY
10th September 2008, 13:27
Thanks for the speedy reply!

Would you happen to know if there any walkthroughs or comments for the demos of QGraphicsView? Because it's a little difficult to piece together how everything works with straight code.

RY
10th September 2008, 13:54
Thanks again for your speedy reply!

If I do draw the items with functions in Qt, would that be using the QPainter class or is there something else?

If it's not too much trouble, could you possible post some example code?

GuL
10th September 2008, 14:00
there is one example here:
http://doc.trolltech.com/4.4/painting-basicdrawing.html

RY
10th September 2008, 14:07
Thanks for your speedy reply!

I'm looking for a more basic example though. Like really basic that only shows you what is absolutely necessary. A lot of the examples are great, but they seem to cram too many concepts into one, so it's difficult to know what is affecting where without comments.

aamer4yu
11th September 2008, 07:21
Didnt you go through Qt Demos ? There are good examples there..
You can start with Colliding mice or Diagram scene examples

RY
19th September 2008, 02:58
For creating a custom QGraphicsItem, what is the bounding rectangle doing? For example in the Colliding Mice Example, why do you need the "adjust" and how do the numbers in QRectF reflect the mouse?

Thank you!

aamer4yu
19th September 2008, 11:49
why do you need the "adjust"
I guess that is to account for pen width. When drawing a line, some more pixels will be occupied in drawing. Hence to account the bounding rect properly, adjust is included. In cases where where pen width is more than one, u will need to modify adjust accordingly.


how do the numbers in QRectF reflect the mouse?
They dont reflect the mouse. They reflect the rectangle that is occupied by the mouse. ie. smallest rectangle in which the mouse will fit in.

Also you might ask what does the rect in shape do ? shape is used in case of collision detection. So when mouse rect in the shape function gets collided, it show collision detection..

RY
1st October 2008, 05:12
Would anyone know if it's possible to create a widget that contains both the QGraphicsView and its scene that is viewable in Main Window?