Results 1 to 9 of 9

Thread: Child windows in QCanvas as a canvas item

  1. #1
    Join Date
    Mar 2006
    Posts
    10
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Child windows in QCanvas as a canvas item

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Child windows in QCanvas as a canvas item

    Quote Originally Posted by incubator
    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.

  3. #3
    Join Date
    Mar 2006
    Posts
    10
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Child windows in QCanvas as a canvas item

    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.)

  4. #4
    Join Date
    Mar 2006
    Posts
    10
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Child windows in QCanvas as a canvas item

    are there no documents that have a detailed explanation on how to use the 2D graphics system in QT ?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Child windows in QCanvas as a canvas item

    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.

  6. #6
    Join Date
    Mar 2006
    Posts
    10
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Child windows in QCanvas as a canvas item

    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

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Child windows in QCanvas as a canvas item

    Ok, let's see...

    Quote Originally Posted by incubator
    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

  8. #8
    Join Date
    Mar 2006
    Posts
    10
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Child windows in QCanvas as a canvas item

    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

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Child windows in QCanvas as a canvas item

    Good, have fun.

Similar Threads

  1. When is the best time to delete a QCanvasItem
    By irudkin in forum Qt Programming
    Replies: 12
    Last Post: 8th March 2007, 21:28
  2. Replies: 3
    Last Post: 17th July 2006, 17:57
  3. Child Windows
    By s_a_white in forum Newbie
    Replies: 1
    Last Post: 16th July 2006, 00:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.