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 can I hide the borders of the cells in a QTableView?
QtWS25 Last Chance

How can I hide the borders of the cells in a QTableView?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 3.9k 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.
  • S Offline
    S Offline
    Simmania
    wrote on 14 Mar 2022, 09:42 last edited by
    #1

    Hi,
    I'm using a QTableView with my own abstract data model. All works fine. But I would like to hide the lines between the cells. I can not find the methods to do that.

    J 1 Reply Last reply 14 Mar 2022, 09:47
    0
    • S Simmania
      14 Mar 2022, 09:42

      Hi,
      I'm using a QTableView with my own abstract data model. All works fine. But I would like to hide the lines between the cells. I can not find the methods to do that.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 14 Mar 2022, 09:47 last edited by
      #2

      @Simmania Search for QTableView in https://doc.qt.io/qt-5/stylesheet-reference.html
      And https://doc.qt.io/qt-5/stylesheet-reference.html#gridline-color-prop

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Simmania
        wrote on 14 Mar 2022, 10:36 last edited by
        #3

        Thx
        I'm new to the stylesheet approach. I tried this to see if I can control the style:

        mTableView->setStyleSheet(QString("QTableView { border-color: red; border-style: solid; border-width: 1px; }"));
        

        But that doesn't work. Is "QTableView" the correct selector?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Simmania
          wrote on 14 Mar 2022, 10:49 last edited by Simmania
          #4

          I found out that this one works:

          mTableView->setStyleSheet(QString("QTableView { gridline-color: red; }"));
          

          But I can not find how to remove the grid.
          How can I find out which properties can be controlled and with values are allowed?

          J 1 Reply Last reply 14 Mar 2022, 11:04
          0
          • S Simmania
            14 Mar 2022, 10:49

            I found out that this one works:

            mTableView->setStyleSheet(QString("QTableView { gridline-color: red; }"));
            

            But I can not find how to remove the grid.
            How can I find out which properties can be controlled and with values are allowed?

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 14 Mar 2022, 11:04 last edited by
            #5

            @Simmania said in How can I hide the borders of the cells in a QTableView?:

            But I can not find how to remove the grid

            Set same color for the grid as is used as background color, then the grid will not be visible.

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Simmania
              wrote on 14 Mar 2022, 11:29 last edited by
              #6

              That is not possible, because I want to color the background of the cells too (can be different per cell).

              J 1 Reply Last reply 14 Mar 2022, 11:45
              0
              • S Simmania
                14 Mar 2022, 11:29

                That is not possible, because I want to color the background of the cells too (can be different per cell).

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 14 Mar 2022, 11:45 last edited by
                #7

                @Simmania Sinse you can use RGBA colors you can simply specify a transparent color for gridline-color (A channel set to0.0).

                mTableView->setStyleSheet(QString("QTableView { gridline-color: rgba(255,0,0,0.0); }"));
                

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

                S 1 Reply Last reply 14 Mar 2022, 12:08
                1
                • J jsulm
                  14 Mar 2022, 11:45

                  @Simmania Sinse you can use RGBA colors you can simply specify a transparent color for gridline-color (A channel set to0.0).

                  mTableView->setStyleSheet(QString("QTableView { gridline-color: rgba(255,0,0,0.0); }"));
                  
                  S Offline
                  S Offline
                  Simmania
                  wrote on 14 Mar 2022, 12:08 last edited by
                  #8

                  @jsulm aah, off course!

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Simmania
                    wrote on 14 Mar 2022, 12:11 last edited by
                    #9

                    I also found this one:

                    mTableView->setShowGrid(false);
                    

                    And it works!

                    With the stylesheets there may be much more control possible, but I have a hard time finding out which selection class to use en what the possible properties are.

                    J 1 Reply Last reply 14 Mar 2022, 12:54
                    2
                    • S Simmania
                      14 Mar 2022, 12:11

                      I also found this one:

                      mTableView->setShowGrid(false);
                      

                      And it works!

                      With the stylesheets there may be much more control possible, but I have a hard time finding out which selection class to use en what the possible properties are.

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 14 Mar 2022, 12:54 last edited by
                      #10

                      @Simmania said in How can I hide the borders of the cells in a QTableView?:

                      mTableView->setShowGrid(false);

                      This is easier of course :-)

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

                      1 Reply Last reply
                      0
                      • D davecotter referenced this topic on 18 Feb 2025, 23:16

                      1/10

                      14 Mar 2022, 09:42

                      • Login

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