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. How to make QTableWidgets full of gridlines
QtWS25 Last Chance

How to make QTableWidgets full of gridlines

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 5 Posters 2.2k 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.
  • J Offline
    J Offline
    jronald
    wrote on 27 Oct 2021, 12:03 last edited by
    #1

    table.png

    On the left is by default, on the right is what's wanted.
    Anyway?

    G 1 Reply Last reply 27 Oct 2021, 12:41
    0
    • J jronald
      28 Oct 2021, 06:37

      On Linux, it's better, though still not perfect. I think it might be the difference between free version and non-free version.
      4afa6108-b095-4d0a-89bc-41c9dd27e7c1-image.png

      B Offline
      B Offline
      Bonnie
      wrote on 28 Oct 2021, 07:40 last edited by
      #9

      @jronald No, that's because on Linux it is using fusion style while Windows ones using windows vista style.
      On Windows it can also be set to use fusion style.
      Take a look at QStyle.

      J 1 Reply Last reply 28 Oct 2021, 08:19
      4
      • J jronald
        27 Oct 2021, 12:03

        table.png

        On the left is by default, on the right is what's wanted.
        Anyway?

        G Offline
        G Offline
        Gojir4
        wrote on 27 Oct 2021, 12:41 last edited by
        #2

        Hi @jronald,

        With stylesheet:
        ui->tableView->setStyleSheet("QTableView{border : 1px solid red}");
        source

        Or using a delegate: (python code)

        class GridDelegate(QStyledItemDelegate):
            def __init__(self, borderColor=None, parent=None):
                super().__init__(parent)
                self.bordelColor = borderColor
        
            def paint(self, painter, option, index):
                painter.save()
                painter.setPen(QColor(self.borderColor or '#aaa'))
                # painter.drawRect(option.rect)
                painter.drawRoundedRect(option.rect, 8, 8)
                painter.restore()
                return super().paint(painter, option, index)
        
        #...
        
        myTableView.setItemDelegate(GridDelegate)
        
        1 Reply Last reply
        0
        • J Offline
          J Offline
          jronald
          wrote on 27 Oct 2021, 12:51 last edited by
          #3

          With stylesheets, how to draw lines between secions of vertical header, and make the color the same as other guide lines that's by default?

          G 2 Replies Last reply 27 Oct 2021, 13:04
          0
          • J jronald
            27 Oct 2021, 12:51

            With stylesheets, how to draw lines between secions of vertical header, and make the color the same as other guide lines that's by default?

            G Offline
            G Offline
            Gojir4
            wrote on 27 Oct 2021, 13:04 last edited by
            #4

            @jronald My bad, that stylesheet was only for table border but not for cells...

            this should work better, but it removes the background color in case you have changed it (see discussion here):
            ui->tableView->setStylesheet("QTableView::item { border: 1px solid red}");

            I didn't find a better solution

            1 Reply Last reply
            0
            • J jronald
              27 Oct 2021, 12:51

              With stylesheets, how to draw lines between secions of vertical header, and make the color the same as other guide lines that's by default?

              G Offline
              G Offline
              Gojir4
              wrote on 27 Oct 2021, 13:39 last edited by
              #5

              @jronald This is probably the solution you're looking for:

              ui->tableView->setStylesheet("QTableView {gridline-color: red}");
              ui->tableView->horizontalHeader()->setStyleSheet("::section{border: 1px solid blue;}");
              ui->tableView->verticalHeader()->setStyleSheet("::section{border: 1px solid green;}");
              
              J 1 Reply Last reply 28 Oct 2021, 04:31
              0
              • G Gojir4
                27 Oct 2021, 13:39

                @jronald This is probably the solution you're looking for:

                ui->tableView->setStylesheet("QTableView {gridline-color: red}");
                ui->tableView->horizontalHeader()->setStyleSheet("::section{border: 1px solid blue;}");
                ui->tableView->verticalHeader()->setStyleSheet("::section{border: 1px solid green;}");
                
                J Offline
                J Offline
                jronald
                wrote on 28 Oct 2021, 04:31 last edited by
                #6

                @Gojir4 said in How to make QTableWidgets full of gridlines:

                ui->tableView->setStylesheet("QTableView {gridline-color: red}");
                ui->tableView->horizontalHeader()->setStyleSheet("::section{border: 1px solid blue;}");
                ui->tableView->verticalHeader()->setStyleSheet("::section{border: 1px solid green;}");

                d03ea014-b02e-4ce2-886e-46ff4591aac8-image.png

                Not perfect

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jronald
                  wrote on 28 Oct 2021, 06:37 last edited by
                  #7

                  On Linux, it's better, though still not perfect. I think it might be the difference between free version and non-free version.
                  4afa6108-b095-4d0a-89bc-41c9dd27e7c1-image.png

                  J B 2 Replies Last reply 28 Oct 2021, 07:02
                  0
                  • J jronald
                    28 Oct 2021, 06:37

                    On Linux, it's better, though still not perfect. I think it might be the difference between free version and non-free version.
                    4afa6108-b095-4d0a-89bc-41c9dd27e7c1-image.png

                    J Online
                    J Online
                    JonB
                    wrote on 28 Oct 2021, 07:02 last edited by JonB
                    #8

                    @jronald said in How to make QTableWidgets full of gridlines:

                    I think it might be the difference between free version and non-free version.

                    I don't think so, since they are identical in this and most respects (the only differences being extras which come with the commercial version, plus The Qt Company's support) :) What induces you to make such a statement?

                    J 1 Reply Last reply 28 Oct 2021, 08:18
                    3
                    • J jronald
                      28 Oct 2021, 06:37

                      On Linux, it's better, though still not perfect. I think it might be the difference between free version and non-free version.
                      4afa6108-b095-4d0a-89bc-41c9dd27e7c1-image.png

                      B Offline
                      B Offline
                      Bonnie
                      wrote on 28 Oct 2021, 07:40 last edited by
                      #9

                      @jronald No, that's because on Linux it is using fusion style while Windows ones using windows vista style.
                      On Windows it can also be set to use fusion style.
                      Take a look at QStyle.

                      J 1 Reply Last reply 28 Oct 2021, 08:19
                      4
                      • J JonB
                        28 Oct 2021, 07:02

                        @jronald said in How to make QTableWidgets full of gridlines:

                        I think it might be the difference between free version and non-free version.

                        I don't think so, since they are identical in this and most respects (the only differences being extras which come with the commercial version, plus The Qt Company's support) :) What induces you to make such a statement?

                        J Offline
                        J Offline
                        jronald
                        wrote on 28 Oct 2021, 08:18 last edited by jronald
                        #10

                        @JonB said in How to make QTableWidgets full of gridlines:

                        I don't think so, since they are identical in this and most respects (the only differences being extras which come with the commercial version, plus The Qt Company's support) :) What induces you to make such a statement?

                        Because it's obvious that tables show as below by default are not as expected, and it's not hard to fix.
                        For a non-free version, if you ask for the company for support for such problems, patches might have been already there.

                        1217c62b-bcb0-43af-8e70-8f76cf5ff0fc-image.png

                        J jsulmJ 2 Replies Last reply 28 Oct 2021, 08:24
                        0
                        • B Bonnie
                          28 Oct 2021, 07:40

                          @jronald No, that's because on Linux it is using fusion style while Windows ones using windows vista style.
                          On Windows it can also be set to use fusion style.
                          Take a look at QStyle.

                          J Offline
                          J Offline
                          jronald
                          wrote on 28 Oct 2021, 08:19 last edited by
                          #11

                          @Bonnie said in How to make QTableWidgets full of gridlines:

                          @jronald No, that's because on Linux it is using fusion style while Windows ones using windows vista style.
                          On Windows it can also be set to use fusion style.
                          Take a look at QStyle.

                          Thanks very much, it must help.

                          1 Reply Last reply
                          0
                          • J jronald
                            28 Oct 2021, 08:18

                            @JonB said in How to make QTableWidgets full of gridlines:

                            I don't think so, since they are identical in this and most respects (the only differences being extras which come with the commercial version, plus The Qt Company's support) :) What induces you to make such a statement?

                            Because it's obvious that tables show as below by default are not as expected, and it's not hard to fix.
                            For a non-free version, if you ask for the company for support for such problems, patches might have been already there.

                            1217c62b-bcb0-43af-8e70-8f76cf5ff0fc-image.png

                            J Online
                            J Online
                            JonB
                            wrote on 28 Oct 2021, 08:24 last edited by
                            #12

                            @jronald said in How to make QTableWidgets full of gridlines:

                            Because it's obvious that tables shows as below by default is not expected, and it's not hard to fix.

                            Since you choose to reply to me, what in the world does this have to do with your statement that the difference is between the commercial and free versions of Qt? You are suggesting to other readers that there is such a difference, which is just misleading.

                            And since you have acknowledged that @Bonnie's answer about your choice of Fusion vs Vista style is the reason for the difference, you know that commercial vs open source is not at issue.

                            J 1 Reply Last reply 28 Oct 2021, 09:38
                            1
                            • J jronald
                              28 Oct 2021, 08:18

                              @JonB said in How to make QTableWidgets full of gridlines:

                              I don't think so, since they are identical in this and most respects (the only differences being extras which come with the commercial version, plus The Qt Company's support) :) What induces you to make such a statement?

                              Because it's obvious that tables show as below by default are not as expected, and it's not hard to fix.
                              For a non-free version, if you ask for the company for support for such problems, patches might have been already there.

                              1217c62b-bcb0-43af-8e70-8f76cf5ff0fc-image.png

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 28 Oct 2021, 08:24 last edited by jsulm
                              #13

                              @jronald said in How to make QTableWidgets full of gridlines:

                              Because it's obvious that tables shows as below by default is not expected, and it's not hard to fix.

                              Do you really think that the only possible explanation for this issue is that "difference between free version and non-free version"?!
                              Open source and commercial Qt use same code base. The only difference is the license and some additional modules/tools available onyl for commercial users. QWidgets module is exactly the same...

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

                              J 1 Reply Last reply 28 Oct 2021, 09:32
                              0
                              • jsulmJ jsulm
                                28 Oct 2021, 08:24

                                @jronald said in How to make QTableWidgets full of gridlines:

                                Because it's obvious that tables shows as below by default is not expected, and it's not hard to fix.

                                Do you really think that the only possible explanation for this issue is that "difference between free version and non-free version"?!
                                Open source and commercial Qt use same code base. The only difference is the license and some additional modules/tools available onyl for commercial users. QWidgets module is exactly the same...

                                J Offline
                                J Offline
                                jronald
                                wrote on 28 Oct 2021, 09:32 last edited by
                                #14

                                @jsulm said in How to make QTableWidgets full of gridlines:

                                Do you really think that the only possible explanation for this issue is that "difference between free version and non-free version"?!
                                Open source and commercial Qt use same code base. The only difference is the license and some additional modules/tools available onyl for commercial users. QWidgets module is exactly the same...

                                Also supports by the company, patches might be there.

                                jsulmJ 1 Reply Last reply 28 Oct 2021, 10:58
                                0
                                • J JonB
                                  28 Oct 2021, 08:24

                                  @jronald said in How to make QTableWidgets full of gridlines:

                                  Because it's obvious that tables shows as below by default is not expected, and it's not hard to fix.

                                  Since you choose to reply to me, what in the world does this have to do with your statement that the difference is between the commercial and free versions of Qt? You are suggesting to other readers that there is such a difference, which is just misleading.

                                  And since you have acknowledged that @Bonnie's answer about your choice of Fusion vs Vista style is the reason for the difference, you know that commercial vs open source is not at issue.

                                  J Offline
                                  J Offline
                                  jronald
                                  wrote on 28 Oct 2021, 09:38 last edited by jronald
                                  #15

                                  @JonB said in How to make QTableWidgets full of gridlines:

                                  @jronald said in How to make QTableWidgets full of gridlines:

                                  Because it's obvious that tables shows as below by default is not expected, and it's not hard to fix.

                                  Since you choose to reply to me, what in the world does this have to do with your statement that the difference is between the commercial and free versions of Qt? You are suggesting to other readers that there is such a difference, which is just misleading.

                                  And since you have acknowledged that @Bonnie's answer about your choice of Fusion vs Vista style is the reason for the difference, you know that commercial vs open source is not at issue.

                                  At first sorry for my grammar, I should review it before posting.

                                  Anyway I think the default style on Windows is not as expected, for a comercial license, the customer can ask for support to fix it.
                                  With fusion style, as the screenshot shows, it is still not perfect.

                                  J 1 Reply Last reply 28 Oct 2021, 09:41
                                  0
                                  • J jronald
                                    28 Oct 2021, 09:38

                                    @JonB said in How to make QTableWidgets full of gridlines:

                                    @jronald said in How to make QTableWidgets full of gridlines:

                                    Because it's obvious that tables shows as below by default is not expected, and it's not hard to fix.

                                    Since you choose to reply to me, what in the world does this have to do with your statement that the difference is between the commercial and free versions of Qt? You are suggesting to other readers that there is such a difference, which is just misleading.

                                    And since you have acknowledged that @Bonnie's answer about your choice of Fusion vs Vista style is the reason for the difference, you know that commercial vs open source is not at issue.

                                    At first sorry for my grammar, I should review it before posting.

                                    Anyway I think the default style on Windows is not as expected, for a comercial license, the customer can ask for support to fix it.
                                    With fusion style, as the screenshot shows, it is still not perfect.

                                    J Online
                                    J Online
                                    JonB
                                    wrote on 28 Oct 2021, 09:41 last edited by
                                    #16

                                    @jronald said in How to make QTableWidgets full of gridlines:

                                    for a comercial license, the customer can ask support to fix it.

                                    I don't know what to say. Get a commercial licence and then see what The Qt Company has to say when you/your end-user tries to ask them to "fix" this (intended) behaviour.

                                    1 Reply Last reply
                                    0
                                    • J jronald
                                      28 Oct 2021, 09:32

                                      @jsulm said in How to make QTableWidgets full of gridlines:

                                      Do you really think that the only possible explanation for this issue is that "difference between free version and non-free version"?!
                                      Open source and commercial Qt use same code base. The only difference is the license and some additional modules/tools available onyl for commercial users. QWidgets module is exactly the same...

                                      Also supports by the company, patches might be there.

                                      jsulmJ Offline
                                      jsulmJ Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on 28 Oct 2021, 10:58 last edited by jsulm
                                      #17

                                      @jronald said in How to make QTableWidgets full of gridlines:

                                      Also supports by the company, patches might be there

                                      Don't know what you mean. What company? What patches? What support?
                                      All Qt patches are merged into mainline and released. The only difference is that open source users do not get Qt binaries for point releses (5.15.x). But open source users can download the source code and build by themselfs...
                                      Support from QtCompany requires a commercial license, yes - but this has NOTHING to do with Qt itself...

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

                                      J 1 Reply Last reply 28 Oct 2021, 13:04
                                      1
                                      • jsulmJ jsulm
                                        28 Oct 2021, 10:58

                                        @jronald said in How to make QTableWidgets full of gridlines:

                                        Also supports by the company, patches might be there

                                        Don't know what you mean. What company? What patches? What support?
                                        All Qt patches are merged into mainline and released. The only difference is that open source users do not get Qt binaries for point releses (5.15.x). But open source users can download the source code and build by themselfs...
                                        Support from QtCompany requires a commercial license, yes - but this has NOTHING to do with Qt itself...

                                        J Offline
                                        J Offline
                                        jronald
                                        wrote on 28 Oct 2021, 13:04 last edited by jronald
                                        #18

                                        @jsulm said in How to make QTableWidgets full of gridlines:

                                        @jronald said in How to make QTableWidgets full of gridlines:

                                        Also supports by the company, patches might be there

                                        Don't know what you mean. What company?

                                        Qt

                                        What patches?

                                        patches to fix the lines in QTableWidget / QTableView

                                        What support?

                                        paid support

                                        All Qt patches are merged into mainline and released. The only difference is that open source users do not get Qt binaries for point releses (5.15.x). But open source users can download the source code and build by themselfs...
                                        Support from QtCompany requires a commercial license, yes - but this has NOTHING to do with Qt itself...

                                        If you are comfortable with the default table styles as in the screenshots below, you are right
                                        alt text

                                        1 Reply Last reply
                                        0

                                        1/18

                                        27 Oct 2021, 12:03

                                        • Login

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