Results 1 to 9 of 9

Thread: how to enable borders in QGraphicsScene?

  1. #1
    Join Date
    May 2008
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default how to enable borders in QGraphicsScene?

    Hello!
    I have a window with couples of regular widgets and some of my own graphics widgets. I join my graphic items to QGraphicScene, then add it to QGraphicsView and then add it to QLayout. After this I can see a thin border around this scene. How to enable this border? Because I have a black backround of my window and all my widgets are black, so this border looks not so nice.

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to enable borders in QGraphicsScene?

    If you like print border from QGraphicsScene draw a QGraphicsLineItem


    to not print drawBackground on view....

    Qt Code:
    1. void GraphicsView::drawBackground(QPainter *painter, const QRectF &rect)
    2. {
    3. setCacheMode(CacheNone); /* cache or not Background QGraphicsView::CacheBackground*/
    4.  
    5. painter->save();
    6. painter->setPen( QPen(Qt::darkGray,1) );
    7. painter->setBrush(QBrush(chessgrid));
    8. painter->drawRect(scene->sceneRect());
    9. painter->restore();
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

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

    as001622 (24th May 2008)

  4. #3
    Join Date
    May 2008
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to enable borders in QGraphicsScene?

    Unfortently, this couldn't solve my problem, but thanks in anyway!

  5. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to enable borders in QGraphicsScene?

    can u show the problem in a snapshot ??

    also try some setSpacing() or setMargin() functions... may be they will help to remove the border

  6. #5
    Join Date
    May 2008
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to enable borders in QGraphicsScene?

    Here is part of my program interface, I can't show it, so it's just to let you now what the problem I have.

    On top you can see a thin line around some shape, so this line is showing arond my QGraphicsView, I wanna to enable this line. I've tryed also setSpacing() and set Margin but it couldn't help. I think that problem is in how QLayout add QGraphicsView in layout, why this line is showing?

  7. #6
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to enable borders in QGraphicsScene?

    QGraphicsView is a sub-class of QFrame. There you have setFrameShadow() and a few others.

  8. The following user says thank you to durbrak for this useful post:

    as001622 (26th May 2008)

  9. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to enable borders in QGraphicsScene?

    try to set setFlat() on graphicsView...
    hope it helps

  10. #8
    Join Date
    May 2008
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to enable borders in QGraphicsScene?

    setFrameShadow(QFrame::Raised) solved my problem. Thanks!

  11. #9
    Join Date
    Apr 2008
    Posts
    1
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Talking Re: how to enable borders in QGraphicsScene?

    I have been stumbling to find the solution to the problem that is opposite to the original issue in this thread -- I want to get rid off the border a the border of the view (I think it's also the border of the view, not border of the scene, as in this thread). Thanks to the information here, I got the solution: setFrameStyle(QFrame::NoFrame);

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.