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. Insert fill circle into cell of QTableWidget
Forum Updated to NodeBB v4.3 + New Features

Insert fill circle into cell of QTableWidget

Scheduled Pinned Locked Moved Solved General and Desktop
88 Posts 5 Posters 40.2k Views 2 Watching
  • 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.
  • mrjjM mrjj

    @juaniyoalm
    Hi, is the value in the model ?
    The delegate can use values from model.
    so the color and size of circle could come from model.

    J Offline
    J Offline
    juaniyoalm
    wrote on last edited by
    #14

    @mrjj

    No, that value is in a c++class. I have to create a custom model... It's ok?? Or I can use a default model??

    mrjjM 1 Reply Last reply
    0
    • J juaniyoalm

      @mrjj

      No, that value is in a c++class. I have to create a custom model... It's ok?? Or I can use a default model??

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #15

      @juaniyoalm
      You can use http://doc.qt.io/qt-5/qstandarditemmodel.html
      if it is. dont have to be custom.
      I though you already had a model ?
      Also is this with a QTableWidget ?
      (it uses a model already )

      J 1 Reply Last reply
      1
      • mrjjM mrjj

        @juaniyoalm
        You can use http://doc.qt.io/qt-5/qstandarditemmodel.html
        if it is. dont have to be custom.
        I though you already had a model ?
        Also is this with a QTableWidget ?
        (it uses a model already )

        J Offline
        J Offline
        juaniyoalm
        wrote on last edited by
        #16

        @mrjj

        No, I use QTableView.

        I used a model to try but I don't know how to implement it

        mrjjM 1 Reply Last reply
        0
        • J juaniyoalm

          @mrjj

          No, I use QTableView.

          I used a model to try but I don't know how to implement it

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #17

          @juaniyoalm
          Super. With view its much easier.
          so you have to construct a model with the data
          that comes from the class.
          Did you make a qstandarditemmodel before ?

          J 1 Reply Last reply
          1
          • mrjjM mrjj

            @juaniyoalm
            Super. With view its much easier.
            so you have to construct a model with the data
            that comes from the class.
            Did you make a qstandarditemmodel before ?

            J Offline
            J Offline
            juaniyoalm
            wrote on last edited by
            #18

            @mrjj
            Yes, I did but without data class

            1 Reply Last reply
            0
            • J Offline
              J Offline
              juaniyoalm
              wrote on last edited by
              #19

              @mrjj
              Do you show me how to make??

              mrjjM 1 Reply Last reply
              0
              • J juaniyoalm

                @mrjj
                Do you show me how to make??

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #20

                @juaniyoalm
                Hi
                Please read about userRoles and setData

                http://doc.qt.io/qt-5/model-view-programming.html
                section Item roles

                you can simply put the color / size in user role, or you can have
                it directly as an item in your model.
                Both ways are fine.
                Then delegate read the user role and use the data.

                1 Reply Last reply
                4
                • J Offline
                  J Offline
                  juaniyoalm
                  wrote on last edited by juaniyoalm
                  #21

                  I read it and I have tried it but my problem is that size circle depends that value of class and colour of background another value of class. I don't know how do it...

                  mrjjM 1 Reply Last reply
                  0
                  • J juaniyoalm

                    I read it and I have tried it but my problem is that size circle depends that value of class and colour of background another value of class. I don't know how do it...

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #22

                    @juaniyoalm
                    Hi
                    Well the delegate cannot go read into other external classes.
                    So you have to at some point take the values from the classes and
                    put into the model.
                    How often does those values change in the classes ?

                    J 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      @juaniyoalm
                      Hi
                      Well the delegate cannot go read into other external classes.
                      So you have to at some point take the values from the classes and
                      put into the model.
                      How often does those values change in the classes ?

                      J Offline
                      J Offline
                      juaniyoalm
                      wrote on last edited by
                      #23

                      @mrjj

                      The parameters will change very often. There will be hundreds of instances of the class and the values ​​will change.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #24

                        The problem is not in the number of instances but rather how you access them.

                        How are you currently handling these differed classes ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        1
                        • J Offline
                          J Offline
                          juaniyoalm
                          wrote on last edited by
                          #25

                          @mrjj @SGaist Hi!!

                          The program will be a simulation of the habitat of fungus and fungivores. I have a world class, which contains a matrix (world), and an array of fungivores. The matrix is composed of cell. The cell class contains an array of fungivores (fungivores that are in that cell) and an int that represents the amount of fungus there is. In the course of the execution the value of fungus and the number of fungivores that there will be in each cell will change. That's what I have to represent in the UI. The amount of fungus will represent it by painting the green cells, with an intensity between 0 and 255, depending on the value, and the amount of fungivors will represent it with a circle, the size of the circle will depend on the value. Once I have this sequential version, I will have to make a parallel version.

                          JonBJ 1 Reply Last reply
                          0
                          • J juaniyoalm

                            @mrjj @SGaist Hi!!

                            The program will be a simulation of the habitat of fungus and fungivores. I have a world class, which contains a matrix (world), and an array of fungivores. The matrix is composed of cell. The cell class contains an array of fungivores (fungivores that are in that cell) and an int that represents the amount of fungus there is. In the course of the execution the value of fungus and the number of fungivores that there will be in each cell will change. That's what I have to represent in the UI. The amount of fungus will represent it by painting the green cells, with an intensity between 0 and 255, depending on the value, and the amount of fungivors will represent it with a circle, the size of the circle will depend on the value. Once I have this sequential version, I will have to make a parallel version.

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #26

                            @juaniyoalm
                            So can you keep those fungus-intensity-ints in (a column in) your model? Then your view can access it.

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #27

                              Is the matrix a two dimensional table ?

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              J 1 Reply Last reply
                              0
                              • SGaistS SGaist

                                Is the matrix a two dimensional table ?

                                J Offline
                                J Offline
                                juaniyoalm
                                wrote on last edited by juaniyoalm
                                #28

                                @SGaist
                                Yes, in each cell there is fungus (int value) and fungivores (array of fungivores).

                                I've tried pass QPair or Qlist to QStandarItemModel but is not posible cast to qvariant

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #29

                                  What are you currently using to store that "matrix" ?

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  1
                                  • J Offline
                                    J Offline
                                    juaniyoalm
                                    wrote on last edited by
                                    #30

                                    Vector<Vector<Cell>>

                                    1 Reply Last reply
                                    0
                                    • J Offline
                                      J Offline
                                      juaniyoalm
                                      wrote on last edited by
                                      #31

                                      Some answer please???

                                      1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #32

                                        Please show some patience and allow 24 hours to run before bumping your own thread. This is a community forum where people answer on their own time. They might not even live in the same timezone as you.

                                        As for your current trouble. You can build a QAbstractTableModel that will give access to your matrix. For the specific members of your Cell class, you can use custom roles.

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        J 1 Reply Last reply
                                        2
                                        • SGaistS SGaist

                                          Please show some patience and allow 24 hours to run before bumping your own thread. This is a community forum where people answer on their own time. They might not even live in the same timezone as you.

                                          As for your current trouble. You can build a QAbstractTableModel that will give access to your matrix. For the specific members of your Cell class, you can use custom roles.

                                          J Offline
                                          J Offline
                                          juaniyoalm
                                          wrote on last edited by
                                          #33

                                          @SGaist

                                          I'm sorry, it was my vacation day and I wanted to move forward with the project. I'm sorry.

                                          To assign the matrix to the model simply the model creates a variable of the same type as the matrix and initialize the model I assign it in some way, is it correct? I do not understand the roles very well ...

                                          1 Reply Last reply
                                          0

                                          • Login

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