Results 1 to 7 of 7

Thread: Drawing something at first and avoid redrawing on update() calls

  1. #1
    Join Date
    Aug 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Drawing something at first and avoid redrawing on update() calls

    Hi all,
    I'm working at a monopoly-like game project.
    The game has to draw a path made of spaces, in which some tokens move. So what really changes during the iterations is:
    - tokens position
    - the active space (think about purchase or mortgage actions)
    So I wonder if there is a way to draw all the spaces (their borders, their names..) during the game setup and, during the game itself, tell the paintEvent to paint only what really has changed.

    Thanks in advance.

  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: Drawing something at first and avoid redrawing on update() calls

    Yes and no. Yes - it is possible to request redraws of particular areas only. No - you can't guarantee that paint events will be called only for those regions (as the windowing system may request redraw of your whole window when it's obscured or resized). What you probably want is to draw the permanent content on a pixmap and rendering the pixmap to the widget in paint events before drawing the volatile content.
    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.


  3. #3
    Join Date
    Aug 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drawing something at first and avoid redrawing on update() calls

    Hi wysota, thanks for your answer.
    I spent some time thinking about a new strategy. Essentially, I have different types of spaces, in which I have to draw something additional. For example, a BuildingSpace where I draw the color corresponding to the owner; a CompanySpace, where I draw the colors correspondig to multiple owners..
    I could have a:
    - mainClass, its paintEvent deals with drawing the path, that is spaces with their borders and their names.
    - classes for each type of spaces, each inheriting QWidget. So each class has its own paintEvent, who only cares of drawing additional info and, obviously, the token area inside the space -> so their paintEvents draw inside a region
    In such way, mainClass:aintEvent is called automatically as usual and I will not call it manually.
    Instead, Space classes paintEvents can be called:
    - by mainClass paintEvent when there is a complete redrawing
    - manually by some methods during the game iteration, like when updating a token's position.
    So, in the end, during normal game iterations and excluding events that cause entire redrawing, I'm drawing only spaces that are really changed.

    What do you think about ?

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Drawing something at first and avoid redrawing on update() calls

    Why don't you use a QGraphicsScene and override the paintBackground() member to paint your board? The pieces and whatnot are placed in a layer on top of the background, and can be moved independently, or even animated.

    Basically, you're talking about reimplementing that class anyway, and it provides a great deal more than what you've described in addition to addressing your current problem.

  5. #5
    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: Drawing something at first and avoid redrawing on update() calls

    Quote Originally Posted by jacopo View Post
    So, in the end, during normal game iterations and excluding events that cause entire redrawing, I'm drawing only spaces that are really changed.
    Forget about redrawing only the things that changed. Essentially you'll be doing it this way anyway, regardless of what approach you take. And regardless of what approach you take you won't be able to guarantee that the windowing system will order you to redraw everything. So in the end you have to be prepared to redraw your whole board but you can optimize by checking what are needs to be redrawn in a particular paint event. If you choose Graphics View approach the framework will help you in this task by forcing redraw of only those objects that occupy the exposed area.
    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.


  6. #6
    Join Date
    Aug 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drawing something at first and avoid redrawing on update() calls

    Ok, QGraphicsView seems to be the best solution.

    However, is it possible to build a QGraphicsScene on a polygon that would not be a rectangle ?
    See for example this: http://qt-apps.org/CONTENT/content-pre1/113173-1.png
    I would like to have a QGraphicsScene on the path only, while at center I would have a QWidget.

    Probably it's not possible, but I want to be sure about it.

  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: Drawing something at first and avoid redrawing on update() calls

    You can place any widget over any other but actually you can place a QWidget inside a scene to get the effect you want. Although personally I don't like the screenshot you posted. I think placing such a boring widget inside such a nice board is a waste of creativity. I'm hoping your version will make extensive use of Qt's Animation Framework.
    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.


Similar Threads

  1. Redrawing QGLWidget with 3D+2D graphics
    By bmpix in forum Qt Programming
    Replies: 2
    Last Post: 1st October 2012, 21:10
  2. Error while redrawing using QPainter Class
    By sosanjay in forum Qt Programming
    Replies: 5
    Last Post: 28th December 2009, 12:48
  3. Replies: 9
    Last Post: 3rd December 2009, 19:19
  4. Optimizing redrawing in the scene
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 28th November 2007, 18:00
  5. subclassing or redrawing a lineEdit
    By jayw710 in forum Qt Programming
    Replies: 2
    Last Post: 7th February 2006, 19:26

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.