Results 1 to 3 of 3

Thread: Bug in QGraphicsScene?

  1. #1
    Join Date
    Jun 2009
    Posts
    5

    Default Bug in QGraphicsScene?

    Okay, so I have a dialog widget inside a QGraphicsView, I want a custom background for the view, so I subclassed QGraphicsScene and overloaded the drawBackground() function. All works as expected. However, when I change the QGraphicsView to use OpenGL, the rectangle handed into the drawBackground function covers the entire view.

    Let me give the code first of all:

    Qt Code:
    1. void SceneHandler::drawBackground(QPainter *painter, const QRectF & rect) {
    2.  
    3. QRect source (xoffset, yoffset, rect.width(), rect.height());
    4. painter->drawImage(rect, img, source);
    5.  
    6. qsl << QString::number(rect.x());
    7. qsl << QString::number(rect.y());
    8. qsl << QString::number(rect.width());
    9. qsl << QString::number(rect.height());
    10. qDebug(qsl.join(",").toAscii());
    11. }
    To copy to clipboard, switch view to plain text mode 

    When using the system (default) rasteriser this gives me:
    Qt Code:
    1. 161,263,682,461
    2. 333,299,462,24
    3. 333,299,462,24
    4. 333,301,12,21
    5. 333,299,462,24
    6. 333,301,12,21
    7. 333,301,12,21
    8. 333,301,12,21
    To copy to clipboard, switch view to plain text mode 

    when using OpenGL I get
    Qt Code:
    1. 95,176,682,461
    2. 95,176,682,461
    3. 95,176,682,461
    4. 95,176,682,461
    5. 95,176,682,461
    6. 95,176,682,461
    7. 95,176,682,461
    8. 95,176,682,461
    To copy to clipboard, switch view to plain text mode 

    This causes a whole ton of artifacts, because the background painter is overwriting the entire viewport. Then only the changed widgets are redrawn. You can see this by the fact that when we use the system rasteriser we get widths of 12 as parts of widgets are redrawn. With opengl the width is is always 682.

    Any ideas why this is happening?

  2. #2
    Join Date
    Jan 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Bug in QGraphicsScene?

    As far as I knows it is not possible to update parts of the view when using OpenGL. It is possible if you don't use OpenGL, and that is wat you experienced also.

  3. #3
    Join Date
    Jun 2009
    Posts
    5

    Default Re: Bug in QGraphicsScene?

    Thanks for the help. I fixed the bug in my code. For the record you must include this at the end of the drawBackground() function

    Qt Code:
    1. invalidate(rect, QGraphicsScene::ItemLayer | QGraphicsScene::ForegroundLayer);
    To copy to clipboard, switch view to plain text mode 

    This will insure that the upper layers are invalidated for the same rectangle as the background. It seems odd that Qt doesn't do this by default...

Similar Threads

  1. Replies: 12
    Last Post: 7th September 2011, 16:37
  2. [QGraphicsView] Auto adjusting QGraphicsScene
    By Macok in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2009, 22:31
  3. Replies: 0
    Last Post: 5th March 2009, 06:54
  4. QPixmap display on QGraphicsScene
    By febil in forum Qt Programming
    Replies: 2
    Last Post: 26th February 2009, 09:27
  5. in QGraphicsScene matrix of other QGraphicsScene
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 15th February 2009, 17:27

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.