PDA

View Full Version : Child windows in QCanvas as a canvas item



incubator
17th July 2006, 12:47
I am trying to integrate some sort of database table visualisation thing to link tables with foreign keys like in MS Access or in Toad, but to do this I am confused on what kind of approach to take and which classes to use.

The drawing area should be a QCanvas because I need to draw lines between the child windows (like those windows inside an MDI) to link the tables.

but at the same time this window should also be an MDI and I dont know if using multiple inheritance for this situation is appropriate. (I would like to avoid it in the first place).

Also, I dont really know how I would pass the information from the selected item inside such a child window to another child window (linking 2 tables with a foreign key).
The reason why those tables should be represented with windows is because I need the functionality of resizing and moving those objects inside the canvas (unless there is a better way of course ;) )

I'm still using Qt3 (linux) so I dont have access to the new graphics implementation of Qt4 yet.

wysota
17th July 2006, 14:07
but at the same time this window should also be an MDI and I dont know if using multiple inheritance for this situation is appropriate. (I would like to avoid it in the first place).
It's not appropriate.


The reason why those tables should be represented with windows is because I need the functionality of resizing and moving those objects inside the canvas (unless there is a better way of course ;) )
This can be very easily done with canvas objects. Reimplement mousePress, mouseMove and mouseRelease events for your canvas view, in the mousePressEvent check if an item was hit and if so, check whether it should be moved or resized based on the point clicked. In mouseMoveEvent use move() or moveBy() to move the object and in mouseReleaseEvent note that you shouldn't move the item anymore.

incubator
17th July 2006, 14:51
ah, thanks :)

Perhaps it would be good if I would also have a proper collection of code snippets in how to work with the canvas and custom canvas items as I have no experience yet with 2D graphics in Qt. (well, just some basic from tutorial #1 for Qt 3)

basically about how to draw custom canvas items and fill them with a list of labels, hopefully with layoutmanagement so there would be no need to calculate all the x/y coordinates.
(I imagine I would have to remember some sort of middle x coordinate of each label (or item) in my custom canvas item that I could use as a connection point for a line between 2 tables.)

incubator
18th July 2006, 12:50
are there no documents that have a detailed explanation on how to use the 2D graphics system in QT ?

wysota
18th July 2006, 13:08
Everything is in the docs. What exactly don't you know? Maybe we'll be able to help... I suggest you start by reading QPainter docs.

incubator
18th July 2006, 13:17
I know how to draw basic rects but I dont know how to draw a rect with a list of labels in and how I can detect which one is under the mouse, or how to include checkboxes in a qcanvasitem.
Also, I dont like to work with coordinates, I was wondering if some sortof layoutmanagement can be used inside a qcanvas

wysota
18th July 2006, 13:39
Ok, let's see...


I know how to draw basic rects but I dont know how to draw a rect with a list of labels
Draw the rectangle and then the labels inside. QSimpleRichText may help you here.

in and how I can detect which one is under the mouse,
Label or rectangle?
If the label, then it'll be quite hard if you use QSimpleRichText, so you'd have to do the layout management yourself and store all coordinates of labels. If the rectangle then that's easy, use QCanvas::collisions().

or how to include checkboxes in a qcanvasitem.
Make a custom item and use QStyle::drawControl() with CE_CheckBox as a parameter to draw the checkbox. You'll have to do the clicking stuff yourself by checking the coordinates (that's how QCheckBox does that so you can probably take some ideas from its sources).

Also, I dont like to work with coordinates,
You won't get away from that here.

I was wondering if some sortof layoutmanagement can be used inside a qcanvas
Yes, but... you have to implement it yourself :)

incubator
18th July 2006, 14:39
ah :)
That should help me a bit further.
And yes, its the labels I need to detect under the mouse cursor.

Looks like I have some R&D awaiting for me, should be both fun and challenging :)

wysota
18th July 2006, 14:50
Good, have fun.