Results 1 to 1 of 1

Thread: How to Optimize QGraphicsItem paint function in qtScript

  1. #1

    Default How to Optimize QGraphicsItem paint function in qtScript

    Hi Guys,

    I want to develop Tiled Map Editor in QtScript. I have already tried following things:

    Initially I was making a QGraphicsRectItem for each tile and each Tile Layer was also a QGraphicsRectItem. This worked well for small sized map. But as soon as I made a large map e.g. 300 x 300 cells each 32 x 32 pixels the performance degraded. It took quite long to make all the items and even after they were created scrolling was quite jerky.

    I thought it was due to presence of too many objects in memory (around 90000 per tile-layer)

    So I changed my implementation so that each tile-layer would be a single QGraphicsRectItem and I will logically handle the painting of each layer. Since the size of each such item was very big (32 * 300 x 32 * 300 pixels) paint event which was called on slightest scrolling became the bottle neck.

    The QStyleOptionGraphicsItem received as second parameter of paint does not contain exposedRect and rect in QtScript unlike C++.
    I have also tried to set ItemUsesExtendedStyleOptions flag but I do not get exposedRect or rect in QtScript. So I used graphicsView.mapToScene(0,0) and graphicsView.mapToScene(graphicsView.frameSize.wid th(),graphicsView.frameSize.height()); to calculate the area I need to re-paint myself. Though this improved the performance I faced another issue i.e. sometime while scrolling fast using mouse wheel grid was not painted correctly. If I scroll up and down slowly everything works fine.

    I have used graphicsView.viewport().setAttribute(Qt.WA_StaticC ontents,true); to optimize performance.
    I tried using cacheMode mode but since it did not increase the performance a great deal so I am not using it for now.

    I have following questions:

    1) I have attached a screen-shot and code I am using to draw the grid. Can you guys think of any possible reason why grid is not drawn correctly when I scroll up and down fast using mouse wheel.

    2) Am I doing things the correct way. I mean having a very big item as a layer, is it correct was to do this. Are there any other flags that I can set. I have tried QGraphicsView.DontAdjustForAntialiasing and QGraphicsView.DontSavePainterState but they don't seem any positive effect.

    Any help will be appreciated.
    Attached Images Attached Images
    Attached Files Attached Files

Similar Threads

  1. Custom QGraphicsItem paint function problem
    By andzero in forum Newbie
    Replies: 1
    Last Post: 12th October 2011, 18:35
  2. Help on QGraphicsItem::paint please
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 18th July 2011, 08:11
  3. QGraphicsItem paint not triggered
    By roband915 in forum Qt Programming
    Replies: 9
    Last Post: 31st March 2011, 10:06
  4. Optimize QGraphicsItem update
    By paolom in forum Qt Programming
    Replies: 10
    Last Post: 21st March 2011, 15:29
  5. QtScript : passing array as argument into function
    By derek_r in forum Qt Programming
    Replies: 4
    Last Post: 27th October 2007, 10:46

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.