Results 1 to 8 of 8

Thread: Sublassing QGraphicsLayoutItem

  1. #1
    Join Date
    Jan 2010
    Location
    Turkey
    Posts
    39
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Sublassing QGraphicsLayoutItem

    How exactly can I subclass QGraphicsLayoutItem?
    I write a class that subclass QGraphicsLayoutItem and reimplement sizeHint and setGeometry but when I add my custom item to linear or grid layout. It does not shown?
    What is missing?

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Sublassing QGraphicsLayoutItem

    QGraphicsItem is not a QWidget; it's meant to be displayed when it is placed into a QGraphicsScene which is then viewed with a QGraphicsView. It won't show up in a QLayout. In fact, I'm surprised you're able to add it in the first place.

    A QGraphicsView descends from QWidget, and can be added to a QLayout.

  3. #3
    Join Date
    Jan 2010
    Location
    Turkey
    Posts
    39
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sublassing QGraphicsLayoutItem

    I think you got me wrong. Cause there are existing layouts for QGraphicsView.
    Look at these QGraphicsLinearLayout, QGraphicsGridLayout

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Sublassing QGraphicsLayoutItem

    In your original post, you were talking about a QGraphicsItem, not a QGraphicsView.

    Maybe you could post a short example that demonstrates the problem?

  5. #5
    Join Date
    Jan 2010
    Location
    Turkey
    Posts
    39
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sublassing QGraphicsLayoutItem

    Here my trial.

    Qt Code:
    1. //compositeitem.h
    2.  
    3. class CompositeItem : public QGraphicsLayoutItem,public QGraphicsItemGroup
    4. {
    5. CompositeItem(QString id, QList<QGraphicsWidget *> children);
    6. ~CompositeItem();
    7. QSizeF sizeHint() const;
    8. void setGeometry(const QRectF &rect);
    9. };
    10.  
    11. //compositeitem.cpp
    12. CompositeItem::CompositeItem(QString id,QList<QGraphicsWidget *> children)
    13. {
    14. QGraphicsWidget *child;
    15. foreach(child,children)
    16. {
    17. addToGroup(child);
    18. }
    19. }
    20.  
    21. CompositeItem::~CompositeItem()
    22. {
    23. }
    24.  
    25. QSizeF CompositeItem::sizeHint()
    26. {
    27. ...
    28. }
    29.  
    30. void CompositeItem:: setGeometry(const QRectF &rect)
    31. {
    32. QGraphicsLayoutItem::setGeometry(rect);
    33. }
    34.  
    35. //mainwindow.cpp
    36.  
    37. ui.graphicsView->setScene(scene);
    38.  
    39. QGraphicsLinearLayout *layout = new QGraphicsLinearLayout;
    40. CompositeItem * ci = new CompositeItem(...);
    41. layout->addItem(ci);
    42. QGraphicsWidget *container = new QGraphicsWidget;
    43. container->setLayout(layout);
    44. scene->addItem(container);
    To copy to clipboard, switch view to plain text mode 

    Here i do not see my compositeitem drawing on scene.
    Last edited by onurozcelik; 4th May 2010 at 09:24. Reason: updated contents

  6. #6
    Join Date
    Aug 2008
    Location
    Porto Alegre
    Posts
    65
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sublassing QGraphicsLayoutItem

    Did you solve your problem?

  7. #7
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Sublassing QGraphicsLayoutItem

    What happens if you add your CompositeItem directly to the scene?

    And what is it you expect to see? I don't see any paint() routine or other functions that will cause anything to be displayed.

  8. #8
    Join Date
    Jan 2010
    Location
    Turkey
    Posts
    39
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sublassing QGraphicsLayoutItem

    @GuL I don't solve my problem with this approach. But I write a custom composite item class that acts like a QGraphicsItemGroup, also can be added inside QGraphicsLayout.

    @SixDegrees if I add my composite item directly to scene I see empty scene. There is no paint because I expect to see child items paints themselves.

Similar Threads

  1. AlignAbsolute - QGraphicsLayoutItem
    By onurozcelik in forum Qt Programming
    Replies: 3
    Last Post: 22nd April 2010, 08:17
  2. Replies: 1
    Last Post: 23rd February 2010, 15:57
  3. heightForWidth QGraphicsLayoutItem
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 20th October 2009, 09:14
  4. [newbie] signal/slot with sublassing problem
    By borker in forum Qt Programming
    Replies: 7
    Last Post: 17th April 2009, 13:44
  5. Subclassing QGraphicsTextItem and QGraphicsLayoutItem
    By psih128 in forum Qt Programming
    Replies: 2
    Last Post: 15th October 2008, 20:12

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.