Results 1 to 10 of 10

Thread: GraphicsView update background

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default GraphicsView update background

    Hi,

    I have already enabled updates for the graphicsView, set cacheBackground as the mode for updating the gview. I need to change the background color. WHen I set the colour and invoke update/repaint for the view or viewport nothing happens. When I invoke "fitInView(..sceneRect)" the background is repainted.
    How to update the background using update/repaint/etc ?
    My view settings:
    Qt Code:
    1. ...
    2. m_view->setCacheMode(QGraphicsView::CacheBackground);
    3. m_view->setOptimizationFlag(QGraphicsView::DontClipPainter);
    4. m_view->setOptimizationFlag(QGraphicsView::DontSavePainterState);
    5. m_view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    6. m_view->setRenderHints( QPainter::HighQualityAntialiasing);
    7. m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    8. m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    9. ....
    To copy to clipboard, switch view to plain text mode 

    While initializing the view I can set view->setBackgroundColor(Qt::blue),etc. And it works fine. But how to update the backgroundcolor later?

    Thanks.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

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

    Default Re: GraphicsView update background


  3. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: GraphicsView update background

    setBackgroundBrush overides scene's background. I have a custom background in the scene and do not want to change this. Scene rect is smaller than the view size, and to hide that I need to set the same colour for the view and for the scene.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

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

    Default Re: GraphicsView update background

    In that case try changing the QPalette::Base component of the view's palette.

  5. #5
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: GraphicsView update background

    This do not work:
    Qt Code:
    1. QPalette palette;
    2. palette.setBrush(QPalette::Base,m_colorMap.value("NODTA"));//NODTA-> is my color index
    3. m_view->setPalette(palette);
    4. m_view->repaint(true);
    To copy to clipboard, switch view to plain text mode 

    Still using fitInview -> changes the background. Maybe you have and idea what is invoked in the fitInView? (I know the view is transformed /scaled)

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  6. #6
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: GraphicsView update background

    Ok,

    I might have found the problem. While changing the background, the view(if the cachBackground is enabled) repainted the background from the cache. When I turned off the cachBackground the repainting works. yet, I can't turn off the background cache, because repainting works 10x slower.

    I can reset the cache, but it works slower. Howto update the view background without clearing the cache?(when the cache is enabled) ?

    Kacper
    Last edited by maverick_pol; 27th February 2008 at 13:12.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

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

    Default Re: GraphicsView update background

    Maybe you should manualy call update()?

  8. #8
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: GraphicsView update background

    I tried that already. Nothing happens.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

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

    Default Re: GraphicsView update background

    Don't you think that every update causes the background cache to be regenerated? If so, you can turn off the cache, redraw the background and then turn the cache back on.

  10. #10
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: GraphicsView update background

    Well if you are changing something in the background then naturally you need to reset the cache. As you seem to have discovered, QGraphicsView::resetCachedContent () is the key to that.
    Of course the following repaint will be slower because it needs to regenerate the cache. You can't get away from that.

Similar Threads

  1. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 00:44
  2. Replies: 1
    Last Post: 5th April 2006, 16:44

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.