Results 1 to 8 of 8

Thread: Custom QGraphicsItems

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Custom QGraphicsItems

    Basically the items in a scene form a tree.

    This tree is constructed by passing the pointer of one item as the "parent" of any number of other items.
    These items become the "parent" item's "children".

    Children are positioned relative to their parent, if you move such a parent item, the children move along with it.

    After an items is drawn and its children are then drawn "on top" of it.

    So you don't draw a text item on your item, you simply create a text item as a child of your item.
    By passing your item as the parent to the text item's constructor, as I wrote in comment #2.

    Qt Code:
    1. PostIt::PostIt(QGraphicsItem* parent) : QGraphicsItem(parent){
    2. setFlag(QGraphicsItem::ItemIsMovable);
    3.  
    4. QGraphicsTextItem *text = new QGraphicsTextItem("Hello World", this);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    ReasyEasyPeasy (12th August 2015)

Similar Threads

  1. Replies: 2
    Last Post: 8th December 2010, 10:51
  2. PopupMenu for several QGraphicsItems
    By jobrandt in forum Qt Programming
    Replies: 0
    Last Post: 10th August 2009, 15:00
  3. QGraphicsItems Layers
    By qtuser20 in forum Qt Programming
    Replies: 7
    Last Post: 24th July 2009, 00:21
  4. Replies: 1
    Last Post: 10th September 2008, 16:49
  5. QGraphicsItems on top of each other?
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 18th November 2006, 20:23

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
  •  
Qt is a trademark of The Qt Company.