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. Dynamic handling for QTableWidget
Forum Updated to NodeBB v4.3 + New Features

Dynamic handling for QTableWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 6.2k Views 1 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.
  • P Offline
    P Offline
    Piyush
    wrote on 9 Feb 2018, 06:39 last edited by Piyush 2 Sept 2018, 06:41
    #1

    How can I handle adding/removing rows in a QTableWidget dynamically using Qt Designer?

    Currently, whenever I need to update any row(s) in a tablewidget, I have to update the whole table again. Is there any way by which I can add a row in between and shift all the rows down, like we have for excel?

    Also, while setting any element I am using the following setting any label or any value:

    self.ui.tablewidget1.setItem(0, 0, QTableWidgetItem("Overall Data A"))
    self.ui.tablewidget1.setItem(0, 1, QTableWidgetItem(str("{:.2%}".format(0.02))))

    Screenshot of my table:

    0_1518158355054_Snip.PNG

    I am working on it item by item under edit table widget (Qt Designer), which is really time consuming.

    Also, is there a way i can define some areas as name range in this table and call the data using that name range, like we have in excel.

    J 1 Reply Last reply 9 Feb 2018, 07:48
    0
    • P Piyush
      9 Feb 2018, 06:39

      How can I handle adding/removing rows in a QTableWidget dynamically using Qt Designer?

      Currently, whenever I need to update any row(s) in a tablewidget, I have to update the whole table again. Is there any way by which I can add a row in between and shift all the rows down, like we have for excel?

      Also, while setting any element I am using the following setting any label or any value:

      self.ui.tablewidget1.setItem(0, 0, QTableWidgetItem("Overall Data A"))
      self.ui.tablewidget1.setItem(0, 1, QTableWidgetItem(str("{:.2%}".format(0.02))))

      Screenshot of my table:

      0_1518158355054_Snip.PNG

      I am working on it item by item under edit table widget (Qt Designer), which is really time consuming.

      Also, is there a way i can define some areas as name range in this table and call the data using that name range, like we have in excel.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 9 Feb 2018, 07:48 last edited by
      #2

      @Piyush Simply right click on table widget then "Edit items...". Then you can add/remove columns/rows and you can move them up/down or right/left.

      "Also, while setting any element I am using the following setting any label or any value:" - is this a question?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply 9 Feb 2018, 08:55
      0
      • J jsulm
        9 Feb 2018, 07:48

        @Piyush Simply right click on table widget then "Edit items...". Then you can add/remove columns/rows and you can move them up/down or right/left.

        "Also, while setting any element I am using the following setting any label or any value:" - is this a question?

        P Offline
        P Offline
        Piyush
        wrote on 9 Feb 2018, 08:55 last edited by
        #3

        @jsulm I forgot to mention this earlier, but in this tablewidget i have kept the vertical and horizontal headers as hidden. All the row/column headers in this are actually written on cell itself. Likewise, I have different header on Gray cells.

        In this case if I want to add any value in between then how should I proceed?

        The sample code lines were just for example to show that my header are inserted in cells

        J 1 Reply Last reply 9 Feb 2018, 09:20
        0
        • P Piyush
          9 Feb 2018, 08:55

          @jsulm I forgot to mention this earlier, but in this tablewidget i have kept the vertical and horizontal headers as hidden. All the row/column headers in this are actually written on cell itself. Likewise, I have different header on Gray cells.

          In this case if I want to add any value in between then how should I proceed?

          The sample code lines were just for example to show that my header are inserted in cells

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 9 Feb 2018, 09:20 last edited by
          #4

          @Piyush Maybe I don't understand something, but what's the difference? You still can add/remove rows/columns.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 1 Reply Last reply 12 Feb 2018, 05:45
          0
          • J jsulm
            9 Feb 2018, 09:20

            @Piyush Maybe I don't understand something, but what's the difference? You still can add/remove rows/columns.

            P Offline
            P Offline
            Piyush
            wrote on 12 Feb 2018, 05:45 last edited by Piyush 2 Dec 2018, 05:48
            #5

            @jsulm I am actually using one tablewidget for multiple tables. Therefore, I have not used the column/row header and added the same in form of items in the widget. I have created the tablewidget in the following way:

            Screenshot for edit table, column tab:

            0_1518413900698_77b5c92f-2769-46cc-b502-cb43528e582e-image.png

            Row tab:
            0_1518413985583_b2268b6f-9e8d-49e5-be67-4a0874d1a541-image.png

            Items tab:
            0_1518414040182_d4b023a3-c8b8-4123-b456-c01cd24ea0aa-image.png

            In items tab there will be headings in the grey area. This enables me to add multiple table in single tablewidget.

            So, the issue arrives when I need to add something in the middle. As you said that, we can add/remove rows/columns. But, currently I cannot do that.

            Does that mean I have to redesign the whole tablewidget? Use column and rows tab and then do the editing like I did. Is that correct. Is there any way I can do the same without redesigning? (just add columns/rows and copy paste all the items in one go)

            J 1 Reply Last reply 12 Feb 2018, 05:49
            0
            • P Piyush
              12 Feb 2018, 05:45

              @jsulm I am actually using one tablewidget for multiple tables. Therefore, I have not used the column/row header and added the same in form of items in the widget. I have created the tablewidget in the following way:

              Screenshot for edit table, column tab:

              0_1518413900698_77b5c92f-2769-46cc-b502-cb43528e582e-image.png

              Row tab:
              0_1518413985583_b2268b6f-9e8d-49e5-be67-4a0874d1a541-image.png

              Items tab:
              0_1518414040182_d4b023a3-c8b8-4123-b456-c01cd24ea0aa-image.png

              In items tab there will be headings in the grey area. This enables me to add multiple table in single tablewidget.

              So, the issue arrives when I need to add something in the middle. As you said that, we can add/remove rows/columns. But, currently I cannot do that.

              Does that mean I have to redesign the whole tablewidget? Use column and rows tab and then do the editing like I did. Is that correct. Is there any way I can do the same without redesigning? (just add columns/rows and copy paste all the items in one go)

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 12 Feb 2018, 05:49 last edited by
              #6

              @Piyush If you need to add a row in the middle then first add it via + button, then select it and move it to the place where you want to have it using the up button (arrow shoing up). Is this working?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              P 1 Reply Last reply 12 Feb 2018, 06:33
              0
              • J jsulm
                12 Feb 2018, 05:49

                @Piyush If you need to add a row in the middle then first add it via + button, then select it and move it to the place where you want to have it using the up button (arrow shoing up). Is this working?

                P Offline
                P Offline
                Piyush
                wrote on 12 Feb 2018, 06:33 last edited by
                #7

                @jsulm That is not working. It adds the row on the top which cannot be moved/shifted down using the arrow keys

                mrjjM 1 Reply Last reply 12 Feb 2018, 08:23
                0
                • P Piyush
                  12 Feb 2018, 06:33

                  @jsulm That is not working. It adds the row on the top which cannot be moved/shifted down using the arrow keys

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 12 Feb 2018, 08:23 last edited by
                  #8

                  @Piyush
                  Hi
                  works fine here
                  alt text

                  P 1 Reply Last reply 12 Feb 2018, 09:34
                  0
                  • mrjjM mrjj
                    12 Feb 2018, 08:23

                    @Piyush
                    Hi
                    works fine here
                    alt text

                    P Offline
                    P Offline
                    Piyush
                    wrote on 12 Feb 2018, 09:34 last edited by Piyush 2 Dec 2018, 09:34
                    #9

                    @mrjj please have a look at my previous comment. I have explained the case in that.

                    1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 12 Feb 2018, 10:24 last edited by
                      #10

                      Hi
                      If there is no rows and cols , there can be no items.
                      So im really not sure what you are asking. :)

                      P 1 Reply Last reply 12 Feb 2018, 12:21
                      0
                      • mrjjM mrjj
                        12 Feb 2018, 10:24

                        Hi
                        If there is no rows and cols , there can be no items.
                        So im really not sure what you are asking. :)

                        P Offline
                        P Offline
                        Piyush
                        wrote on 12 Feb 2018, 12:21 last edited by
                        #11

                        @mrjj Hi

                        If we do the following in QT Designer on a blank tablewidget, then we have blank items without any rows/columns appearing under rows/columns tab.

                        0_1518438058823_25123e57-a0dc-43f1-b112-ee01e8a19113-image.png

                        mrjjM J 2 Replies Last reply 12 Feb 2018, 12:28
                        1
                        • P Piyush
                          12 Feb 2018, 12:21

                          @mrjj Hi

                          If we do the following in QT Designer on a blank tablewidget, then we have blank items without any rows/columns appearing under rows/columns tab.

                          0_1518438058823_25123e57-a0dc-43f1-b112-ee01e8a19113-image.png

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 12 Feb 2018, 12:28 last edited by
                          #12

                          @Piyush
                          Ahh , in that way :)
                          yeah that is the same it seems,
                          except u cant move rows up and down as they are not there :)
                          Hmm, yes i see your point. its then not possible to add row in the middle since rows before and after
                          do not really exists for it.

                          1 Reply Last reply
                          0
                          • P Piyush
                            12 Feb 2018, 12:21

                            @mrjj Hi

                            If we do the following in QT Designer on a blank tablewidget, then we have blank items without any rows/columns appearing under rows/columns tab.

                            0_1518438058823_25123e57-a0dc-43f1-b112-ee01e8a19113-image.png

                            J Offline
                            J Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on 12 Feb 2018, 12:35 last edited by
                            #13

                            @Piyush What if you don't set fix number of rows and columns? Just add everything in this item editor.

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            P 1 Reply Last reply 13 Feb 2018, 03:50
                            0
                            • J jsulm
                              12 Feb 2018, 12:35

                              @Piyush What if you don't set fix number of rows and columns? Just add everything in this item editor.

                              P Offline
                              P Offline
                              Piyush
                              wrote on 13 Feb 2018, 03:50 last edited by
                              #14

                              @jsulm If we do not set fix number of rows/columns, then we first need to add rows/columns from rows/columns tab. Then it becomes dynamic in the way that we can move rows up/down/delete. Thanks.

                              @mrjj Yeah. I will have to make it again in a dynamic way. Thanks for the discussion.

                              1 Reply Last reply
                              0

                              1/14

                              9 Feb 2018, 06:39

                              • Login

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