Results 1 to 6 of 6

Thread: QGraphicsItem or QGraphicsProxyWidget?

  1. #1
    Join Date
    Jan 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsItem or QGraphicsProxyWidget?

    Hi,

    I need to create an image as below
    Attachment 3604
    It contains:
    1) one or more nodes with a text label. The node is not filled when created, but will be filled with progress
    2) there are one or more ports on each node connecting them together

    I first looked at the Diagram Scene example, but I'll need the port(s) to know which node connecting to which port and also need to add text to the node.

    Should I subclass QGraphicsItem or QGraphicsProxyWidget or something else? Thanks in advance.
    Attached Images Attached Images

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

    Default Re: QGraphicsItem or QGraphicsProxyWidget?

    Definitely not proxy widget. I'd subclass QGraphicsRectItem or QGraphicsTextItem or even compose the item from one rect item, one text item and a couple of ellipse items (or others) for the ports.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItem or QGraphicsProxyWidget?

    Thanks. I understood sub-class QGraphicsRectItem and QGraphicsTextItem. What do you mean by "compose the item from one rect item, one text item and a couple of ellipse items (or others) for the ports"? Have a class that contains a QGraphicsRectItem, QGraphicsTextItem, and ports? What will my paint method look like?
    TNG

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

    Default Re: QGraphicsItem or QGraphicsProxyWidget?

    Quote Originally Posted by ttvo View Post
    What will my paint method look like?
    You won't have one.

    Qt Code:
    1. QGraphicsRectItem *rect = new QGraphicsRectItem(QRectF(-50, -25, 100, 50));
    2. rect->setFlags(QGraphicsItem::ItemIsMovable);
    3. QGraphicsEllipseItem *portN = new QGraphicsEllipseItem(QRectF(-5, -5, 10, 10), rect);
    4. portN->setPos(0, -25);
    5. QGraphicsEllipseItem *portS = new QGraphicsEllipseItem(QRectF(-5, -5, 10, 10), rect);
    6. portS->setPos(0, 25);
    7. scene.addItem(rect);
    8. v.setScene(&scene);
    9. v.show();
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    ttvo (27th August 2009)

  6. #5
    Join Date
    Jan 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItem or QGraphicsProxyWidget?

    Great, that works. I decided to subclass QGraphicsTextItem to include the draw of its boundary, eliminating the need for the QGraphicsRectItem *rect. So the ports are children of my custom text, but how am I going to be able to query how many ports a given custom text item has?

    Should I make the ports as member variable of my custom text? If so, will I need to override the paint method to draw the ports (of type QGraphicsEllipseItem or QGraphicsRectItem). Thanks.

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

    Default Re: QGraphicsItem or QGraphicsProxyWidget?

    Quote Originally Posted by ttvo View Post
    Great, that works. I decided to subclass QGraphicsTextItem to include the draw of its boundary, eliminating the need for the QGraphicsRectItem *rect. So the ports are children of my custom text, but how am I going to be able to query how many ports a given custom text item has?
    You need to provide some API for this in your subclass.

    Should I make the ports as member variable of my custom text? If so, will I need to override the paint method to draw the ports (of type QGraphicsEllipseItem or QGraphicsRectItem). Thanks.
    Why does informing one object about a state of another object require reimplementing its drawing routines?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 25th March 2011, 09:18
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  3. Replies: 11
    Last Post: 2nd July 2009, 00:41
  4. Replies: 1
    Last Post: 25th February 2009, 00:34
  5. Multiple Inheritance for QGraphicsItem
    By pankaj.patil in forum Qt Programming
    Replies: 2
    Last Post: 1st July 2008, 14:49

Tags for this Thread

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.