Results 1 to 3 of 3

Thread: QGraphicsItemGroup problem

  1. #1
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsItemGroup problem

    The new Graphics View framework is great, but I'm having a problem with grouping items. In the example below, only the text item not in the group can be edited. How can I allow the user to edit text items in groups?
    Thanks,
    Wesley

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[]) {
    4. QApplication app(argc, argv);
    5. QGraphicsScene *scene = new QGraphicsScene(&win);
    6.  
    7. QGraphicsTextItem *textItem = new QGraphicsTextItem("In a Group", NULL, scene);
    8. textItem->setPos(50, 50);
    9. textItem->setTextInteractionFlags(Qt::TextEditable|Qt::TextSelectableByMouse);
    10. QGraphicsItemGroup *group = new QGraphicsItemGroup(NULL, scene);
    11. group->addToGroup(textItem);
    12.  
    13. QGraphicsTextItem *textItem2 = new QGraphicsTextItem("Not in a Group", NULL, scene);
    14. textItem2->setPos(50, 10);
    15. textItem2->setTextInteractionFlags(Qt::TextEditable|Qt::TextSelectableByMouse);
    16.  
    17. win.setScene(scene);
    18. win.show();
    19. app.exec();
    20. return 0;
    21. }
    To copy to clipboard, switch view to plain text mode 
    ImageRocket - My Qt4-based image editing program
    Project Page / Screenshots / Source

  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: QGraphicsItemGroup problem

    I think you won't be able to achieve that without subclassing QGraphicsItemGroup. Basically that class is a QGraphicsItem subclass which by itself doesn't allow text interaction (as it doesn't even know what text is). So the thing you should probably do is to subclass the group item and introduce that functionality (by forwarding whatever needs to be forwarded to activate the text edition of the text item).

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

    init2null (8th November 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsItemGroup problem

    There are two ways to make it work, although this isn't really what QGraphicsItemGroup is for; it's correct that you can achieve this easily with a regular QGraphicsItem parent (which already supports grouping).

    Option 1) Create a group item subclass that forwards key press and release events to the text item.

    Option 2) Subclass the text item, then reimplent QGraphicsTextItem::sceneEvent() to intercept the mouse and key events for the text item before they are dispatched to the group item.

    Good luck :-).
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

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

    init2null (27th November 2006)

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.