Results 1 to 5 of 5

Thread: QGraphicsView best way to draw fixed (static) background

  1. #1
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default QGraphicsView best way to draw fixed (static) background

    I've reimplemented QGraphicsView::drawBackground() to draw some grid lines, and now I want to draw a static background behind them. In particular, I'd like a gradient that isn't affected by the view transform, scrolling, etc.

    Does it make more sense to do draw this background under the grid lines in my drawBackground() reimplementation (using e.g., this method, or to give the QGraphicsView a transparent background and put it on top of another QWidget to draw the background?

  2. #2
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default Re: QGraphicsView best way to draw fixed (static) background

    Perhaps a better way to ask this question:

    If I make the background of a QGraphicsView transparent, and put it on top of another widget, will that widget need to be redrawn whenever the QGraphicsView is redrawn? If so, there isn't much benefit to that approach. If not, I imagine it would be much faster.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsView best way to draw fixed (static) background

    Set a custom widget with reimplemented paintEvent() as the viewport of the Graphics View or set a custom brush as Base component of the standard viewport's palette.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    wayfaerer (22nd May 2012)

  5. #4
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default Re: QGraphicsView best way to draw fixed (static) background

    I managed to get it working using style sheets, i.e.,

    Qt Code:
    1. myView->setStyleSheet("QGraphicsView {background: qradialgradient(cx:0.5, cy:0.5, fx:0.5, fy:0.5, radius: 1, stop:0 white, stop:1 gray)}");
    To copy to clipboard, switch view to plain text mode 

    Is that roughly the same thing? In particular I'm really curious whether or not the gradient from the style sheet is continuously being redrawn or not.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsView best way to draw fixed (static) background

    Roughly yes. It depends what you mean by "redrawn". It is redrawn but the image of the background should be taken from the backingstore so the actual painting routine of the widget should not be called.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    wayfaerer (23rd May 2012)

Similar Threads

  1. Replies: 2
    Last Post: 20th February 2012, 07:30
  2. how to draw background color of a label
    By gauravg in forum Qt Programming
    Replies: 1
    Last Post: 1st November 2011, 03:46
  3. Replies: 5
    Last Post: 24th June 2011, 12:07
  4. Static/Fixed rows and columns in a QTreeView
    By code_talker in forum Qt Programming
    Replies: 0
    Last Post: 27th April 2011, 13:00
  5. Replies: 1
    Last Post: 25th June 2010, 18:31

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.