Draw cells of a board quickly
-
Hello everyone, I am trying to make a small simulation project which I need to draw a board of around 6500 cells representing animals and update it to present their movements. Here is an example:
Right now, I am drawing each cell individually. Each cell is a QPushButton and all the cells are grouped in a grid layout.
Each time I made an update, I need to redraw the whole grid layout again and it usually takes me 2-3 seconds which is not very effective in term of time. I would like to know are there ways which I can improve my speed?
Thank you and have a good day! -
Hello everyone, I am trying to make a small simulation project which I need to draw a board of around 6500 cells representing animals and update it to present their movements. Here is an example:
Right now, I am drawing each cell individually. Each cell is a QPushButton and all the cells are grouped in a grid layout.
Each time I made an update, I need to redraw the whole grid layout again and it usually takes me 2-3 seconds which is not very effective in term of time. I would like to know are there ways which I can improve my speed?
Thank you and have a good day!@tjktak1002
Depends what you are using now to draw, which you don't say.One possibility would be to build a complete bitmap image of the whole lot and then show it. Another possibility, if the data arrives cumulatively and you want to show would be to accumulate a bunch of new data updates before showing, e.g. on a timer. Many possibilities.
-
@JonB hello, i would like to know if I use QImage would it improve my drawing time.
Right now I create each cell as a QPushButton and present all the cells in a gridlayout -
@JonB hello, i would like to know if I use QImage would it improve my drawing time.
Right now I create each cell as a QPushButton and present all the cells in a gridlayout@tjktak1002 said in Draw cells of a board quickly:
Right now I create each cell as a QPushButton and present all the cells in a gridlayout
Are you serious? That would be 6500
QPushButton
s to add and draw!it usually takes me 2-3 seconds
I'm surprised it isn't longer!
You cannot possibly be talking about interchanging drawing buttons versus using an image, they are like apples & pears,
Forget asking about efficiency of drawing for the moment. What are you actually wanting to achieve? I thought it as some kind of drawing, why in the world would you want all the points to be buttons?
I need to draw a board of around 6500 cells representing animals and update it to present their movements
You will want to use QGraphicsScene.
-
@tjktak1002 said in Draw cells of a board quickly:
Right now I create each cell as a QPushButton and present all the cells in a gridlayout
Are you serious? That would be 6500
QPushButton
s to add and draw!it usually takes me 2-3 seconds
I'm surprised it isn't longer!
You cannot possibly be talking about interchanging drawing buttons versus using an image, they are like apples & pears,
Forget asking about efficiency of drawing for the moment. What are you actually wanting to achieve? I thought it as some kind of drawing, why in the world would you want all the points to be buttons?
I need to draw a board of around 6500 cells representing animals and update it to present their movements
You will want to use QGraphicsScene.
@JonB haha I knew all the buttons is too much.
I'm super new to QT and I have absolutely no idea how to draw a board with 6500 cells. And using buttons and grid layout is kinda simpler for me.
Right now I just need a way to display a board of 127x53 which can be updated and redrawn as fast as possible. -
@tjktak1002 said in Draw cells of a board quickly:
Right now I create each cell as a QPushButton and present all the cells in a gridlayout
Are you serious? That would be 6500
QPushButton
s to add and draw!it usually takes me 2-3 seconds
I'm surprised it isn't longer!
You cannot possibly be talking about interchanging drawing buttons versus using an image, they are like apples & pears,
Forget asking about efficiency of drawing for the moment. What are you actually wanting to achieve? I thought it as some kind of drawing, why in the world would you want all the points to be buttons?
I need to draw a board of around 6500 cells representing animals and update it to present their movements
You will want to use QGraphicsScene.
@JonB said in Draw cells of a board quickly:
You will want to use QGraphicsScene.
-
@JonB haha I knew all the buttons is too much.
I'm super new to QT and I have absolutely no idea how to draw a board with 6500 cells. And using buttons and grid layout is kinda simpler for me.
Right now I just need a way to display a board of 127x53 which can be updated and redrawn as fast as possible.@tjktak1002 create a QImage and you can set color to each pixel. Then paint this image. If one pixel is not big enough for one cell, use 4 and so on.
-
@JonB haha I knew all the buttons is too much.
I'm super new to QT and I have absolutely no idea how to draw a board with 6500 cells. And using buttons and grid layout is kinda simpler for me.
Right now I just need a way to display a board of 127x53 which can be updated and redrawn as fast as possible.@tjktak1002
If you want to be able to interact with or address the items [animals :) ] then certainly graphics items.
If you just want to recalculate a bitmap like your picture shows and produce a complete new "board" in one go as fast as possible then produce a non-interactive image like @JoeCFD suggests. -
@tjktak1002
If you want to be able to interact with or address the items [animals :) ] then certainly graphics items.
If you just want to recalculate a bitmap like your picture shows and produce a complete new "board" in one go as fast as possible then produce a non-interactive image like @JoeCFD suggests.