Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Draw cells of a board quickly

Draw cells of a board quickly

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 906 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tjktak1002
    wrote on 3 Aug 2022, 13:32 last edited by tjktak1002 8 Mar 2022, 13:59
    #1

    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:
    alt image
    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!

    J 1 Reply Last reply 3 Aug 2022, 13:52
    0
    • T tjktak1002
      3 Aug 2022, 13:32

      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:
      alt image
      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!

      J Offline
      J Offline
      JonB
      wrote on 3 Aug 2022, 13:52 last edited by
      #2

      @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.

      1 Reply Last reply
      3
      • T Offline
        T Offline
        tjktak1002
        wrote on 3 Aug 2022, 14:00 last edited by tjktak1002 8 Mar 2022, 14:03
        #3

        @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

        J 1 Reply Last reply 3 Aug 2022, 14:11
        0
        • T tjktak1002
          3 Aug 2022, 14:00

          @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

          J Offline
          J Offline
          JonB
          wrote on 3 Aug 2022, 14:11 last edited by JonB 8 Mar 2022, 14:14
          #4

          @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 QPushButtons 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.

          T J 2 Replies Last reply 3 Aug 2022, 14:26
          0
          • J JonB
            3 Aug 2022, 14:11

            @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 QPushButtons 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.

            T Offline
            T Offline
            tjktak1002
            wrote on 3 Aug 2022, 14:26 last edited by
            #5

            @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.

            J J 2 Replies Last reply 3 Aug 2022, 15:08
            0
            • J JonB
              3 Aug 2022, 14:11

              @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 QPushButtons 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.

              J Offline
              J Offline
              JonB
              wrote on 3 Aug 2022, 14:45 last edited by JonB 8 Mar 2022, 14:45
              #6

              @JonB said in Draw cells of a board quickly:

              You will want to use QGraphicsScene.

              1 Reply Last reply
              1
              • T tjktak1002
                3 Aug 2022, 14:26

                @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.

                J Offline
                J Offline
                JoeCFD
                wrote on 3 Aug 2022, 15:08 last edited by JoeCFD 8 Mar 2022, 15:10
                #7

                @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.

                1 Reply Last reply
                2
                • T tjktak1002
                  3 Aug 2022, 14:26

                  @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.

                  J Offline
                  J Offline
                  JonB
                  wrote on 3 Aug 2022, 18:49 last edited by JonB 8 Mar 2022, 18:50
                  #8

                  @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.

                  T 1 Reply Last reply 5 Aug 2022, 08:03
                  2
                  • J JonB
                    3 Aug 2022, 18:49

                    @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.

                    T Offline
                    T Offline
                    tjktak1002
                    wrote on 5 Aug 2022, 08:03 last edited by
                    #9

                    @JonB @JoeCFD Hello again, I update from using QPushButton to using QImage. Now, it only took me around 0,2 seconds for each update.
                    Thank you very much for your help. :D

                    1 Reply Last reply
                    1

                    3/9

                    3 Aug 2022, 14:00

                    topic:navigator.unread, 6
                    • Login

                    • Login or register to search.
                    3 out of 9
                    • First post
                      3/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved