Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Solved Insert fill circle into cell of QTableWidget

    General and Desktop
    5
    88
    20622
    Loading More Posts
    • 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.
    • mrjj
      mrjj Lifetime Qt Champion @juaniyoalm last edited by

      @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 1 Reply Last reply Reply Quote 1
      • J
        juaniyoalm @mrjj last edited by

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

        mrjj 1 Reply Last reply Reply Quote 0
        • mrjj
          mrjj Lifetime Qt Champion @juaniyoalm last edited by

          @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 Reply Quote 1
          • J
            juaniyoalm @mrjj last edited by

            @mrjj

            No, I use QTableView.

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

            mrjj 1 Reply Last reply Reply Quote 0
            • mrjj
              mrjj Lifetime Qt Champion @juaniyoalm last edited by

              @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 Reply Quote 1
              • J
                juaniyoalm @mrjj last edited by

                @mrjj
                Yes, I did but without data class

                1 Reply Last reply Reply Quote 0
                • J
                  juaniyoalm last edited by

                  @mrjj
                  Do you show me how to make??

                  mrjj 1 Reply Last reply Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion @juaniyoalm last edited by

                    @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 Reply Quote 4
                    • J
                      juaniyoalm last edited by 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...

                      mrjj 1 Reply Last reply Reply Quote 0
                      • mrjj
                        mrjj Lifetime Qt Champion @juaniyoalm last edited by

                        @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 Reply Quote 1
                        • J
                          juaniyoalm @mrjj last edited by

                          @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 Reply Quote 0
                          • SGaist
                            SGaist Lifetime Qt Champion last edited by

                            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 Reply Quote 1
                            • J
                              juaniyoalm last edited by

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

                              JonB 1 Reply Last reply Reply Quote 0
                              • JonB
                                JonB @juaniyoalm last edited by JonB

                                @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 Reply Quote 0
                                • SGaist
                                  SGaist Lifetime Qt Champion last edited by

                                  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 Reply Quote 0
                                  • J
                                    juaniyoalm @SGaist last edited by juaniyoalm

                                    @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 Reply Quote 0
                                    • SGaist
                                      SGaist Lifetime Qt Champion last edited by

                                      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 Reply Quote 1
                                      • J
                                        juaniyoalm last edited by

                                        Vector<Vector<Cell>>

                                        1 Reply Last reply Reply Quote 0
                                        • J
                                          juaniyoalm last edited by

                                          Some answer please???

                                          1 Reply Last reply Reply Quote 0
                                          • SGaist
                                            SGaist Lifetime Qt Champion last edited by

                                            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 Reply Quote 2
                                            • First post
                                              Last post