Results 1 to 4 of 4

Thread: GraphicsView: how to avoid animated background when animating sceneRect

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default GraphicsView: how to avoid animated background when animating sceneRect

    Hi,

    I'm using the GraphicsView framework to realize a custom 2D GUI. I created the different menu screens in Photoshop, and separately exported the background image on the one hand, and transparent (PNG) images that I place in the different menu screens on the other hand. Each of my menu screen is realized by a class I created, which extends QGraphicsObject. In the QGraphicsView, where I setup the QGraphicsScene, I call
    Qt Code:
    1. QGraphicsScene::setBackgroundBrush()
    To copy to clipboard, switch view to plain text mode 
    on it to set the background image.

    Since I want menu transitions in the "swipe left/right" fashion (i.e. one menu flies out of the view, e.g. to the left, and the next menu flies into the view from the right), I decided to arrange all the menus (QGraphicsObjects) spatially in the QGraphicsScene next to each other. Using the State machine framework and animations framework, I have one state per menu screen, and I'm assigning the QGraphicsView's sceneRect property to a QRectF for each state independently.

    Generally this approach works, and I get smooth menu-to-menu transitions. However, the transitions do not look right. What I want (expect) is that the background image always stays static, "as it is" (regardless that sceneRect is animated), i.e. I'd expect that only the transparent parts of my menu screens are "flying" in/out of the view from the left/right. However, unforunately the background itself does also move, i.e. it is as if QT has taken a screenshot of the view right at the start, and one at the end of the animation, and then animate between the two screenshots.

    Is there a way I can force the background to be completely static anyways?

    Cheers!

  2. #2
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GraphicsView: how to avoid animated background when animating sceneRect

    i cant complete visualize you problem. maybe some screenshot or even better the minimal source code who reproduce your problem.

    meanwile you maybe try some one of this options
    - draw background in the view not the scene. set QGrapicsView::setBackgroundBrush(),
    - reimplement QGraphicsView::drawBackground() this provide more control over how painting the background

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: GraphicsView: how to avoid animated background when animating sceneRect

    You might also try one of the caching options on the QGraphicsItem that holds the images. This was vital in my app to allow smooth rubber banding over a complex background graphic. Using caching on the graphic meant that it would only be physically redrawn when the content or size changed; all the rest of the time it was simply blitted from the cache, with no noticeable flicker at all.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QGraphicsscene.sceneRect on Windows platform
    By sanku3 in forum Qt Programming
    Replies: 0
    Last Post: 26th September 2011, 08:12
  2. bad sceneRect with scaled text
    By koosh in forum Qt Programming
    Replies: 14
    Last Post: 10th July 2008, 19:29
  3. put image on scenerect
    By dreamer in forum Qt Programming
    Replies: 3
    Last Post: 13th May 2008, 06:55
  4. GraphicsView update background
    By maverick_pol in forum Qt Programming
    Replies: 9
    Last Post: 27th February 2008, 19:25
  5. QGraphicsScene: evolution of sceneRect
    By Pieter from Belgium in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2006, 15:11

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
  •  
Qt is a trademark of The Qt Company.