Results 1 to 5 of 5

Thread: QGraphicsWidgets on QGraphicsGridLayout

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

    Question QGraphicsWidgets on QGraphicsGridLayout

    Hi

    I subclass QGraphicsWidget and override boundingRect and paint methods.

    Here is what I did shortly
    Qt Code:
    1. CustomItem :: CustomItem()
    2. {
    3. pen = QPen(QBrush(Qt::gray),5,Qt::SolidLine,Qt::RoundCap,Qt::BevelJoin);
    4. }
    5. CustomItem :: ~CustomItem()
    6. {
    7. }
    8.  
    9. QRectF CustomItem::boundingRect() const
    10. {
    11. return QRectF(0,0,102,5);
    12. }
    13.  
    14. void CustomItem::paint(QPainter *painter,...)
    15. {
    16. painter->setPen(pen);
    17. painter->drawLine(0,0,100,0);
    18. }
    To copy to clipboard, switch view to plain text mode 

    And I added my CustomItem(s) to QGraphicsGridLayout

    For this I used
    Qt Code:
    1. QGraphicsGridLayout *grid = new QGraphicsGridLayout;
    2.  
    3. CustomItem *custom1 = new CustomItem;
    4. CustomItem *custom2 = new CustomItem;
    5.  
    6. grid->addItem(custom1,0,1);
    7. grid->addItem(custom2,0,2);
    8.  
    9. QGraphicsWidget *container = new QGraphicsWidget;
    10. container->setLayout(grid);
    11.  
    12. scene->addItem(container);
    To copy to clipboard, switch view to plain text mode 

    When I do this
    Two custom items had painted on each other(I guess because of paint draws them on same coordinates)
    But I want them to paint one after another, I assume grid layout does it for me but it does not

    How can I overcome this?

    Note: I use QGraphicsWidget class instead of QGraphicsItem or QGraphicsLineItem because I think I may easily
    create my user interface without supplying coordinates for each item.

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QGraphicsWidgets on QGraphicsGridLayout

    I think subclassing boundingRect is not enough. See the documentation for QLayoutItem.
    It's nice to be important but it's more important to be nice.

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

    Thumbs up Re: QGraphicsWidgets on QGraphicsGridLayout

    Thanks for your reply

    I solved the problem
    İf you want to add custom item to QGraphicsGridLayout you should give a fixed row or column size with
    Qt Code:
    1. setFixedColumnWidth/setFixedRowHeight
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QGraphicsWidgets on QGraphicsGridLayout

    That sounds like a short term solution and not the ultimate solution that works also when you have two items in a rows / column that want to have a different size.
    It's nice to be important but it's more important to be nice.

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

    Lightbulb Re: QGraphicsWidgets on QGraphicsGridLayout

    Quote Originally Posted by axeljaeger View Post
    That sounds like a short term solution and not the ultimate solution that works also when you have two items in a rows / column that want to have a different size.
    You may be right. In a situation you mention in your reply we may use QGraphicsItemGroup or something like that.

Similar Threads

  1. QGraphicsGridLayout Broken
    By oberlus in forum Qt Programming
    Replies: 1
    Last Post: 27th August 2010, 11:32
  2. Replies: 1
    Last Post: 10th January 2010, 20:51

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.