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. After hiding the header in the qtablewidget, the left and top borders display abnormally
Qt 6.11 is out! See what's new in the release blog

After hiding the header in the qtablewidget, the left and top borders display abnormally

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 907 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.
  • J Offline
    J Offline
    John Van
    wrote on last edited by John Van
    #1

    1111.png
    The right and bottom borders display normally, but the left and top borders disappear.

    T 1 Reply Last reply
    0
    • J John Van

      1111.png
      The right and bottom borders display normally, but the left and top borders disappear.

      T Offline
      T Offline
      Tink
      wrote on last edited by
      #2

      Those are the gridlines, it is intended this way.

      J 1 Reply Last reply
      0
      • T Tink

        Those are the gridlines, it is intended this way.

        J Offline
        J Offline
        John Van
        wrote on last edited by
        #3

        @Tink Thanks for your reply.
        Is there a way to display the upper left grid line as well?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          CPPUIX
          wrote on last edited by
          #4

          Hi,

          What about customizing the items? Something like this:

          QTableWidget::item
          {
          	border: 1px solid white;
          }
          

          But this will change all items.

          Without this stylesheet:

          QTableWidgetItemsBorderWithout.png

          With this stylesheet:

          QTableWidgetItemsBorder.png

          Note: this is not the grid line, but the items' borders, so it's a workaround.

          An actual solution would probably require setting a margin for whatever contains the view, I couldn't find out how to do that, as neither setting the table nor its viewport's margins worked.

          J 1 Reply Last reply
          0
          • C CPPUIX

            Hi,

            What about customizing the items? Something like this:

            QTableWidget::item
            {
            	border: 1px solid white;
            }
            

            But this will change all items.

            Without this stylesheet:

            QTableWidgetItemsBorderWithout.png

            With this stylesheet:

            QTableWidgetItemsBorder.png

            Note: this is not the grid line, but the items' borders, so it's a workaround.

            An actual solution would probably require setting a margin for whatever contains the view, I couldn't find out how to do that, as neither setting the table nor its viewport's margins worked.

            J Offline
            J Offline
            John Van
            wrote on last edited by
            #5

            @Abderrahmene_Rayene Thanks for your reply.
            In the end, I used CustomiDelegate, and the stylesheet of the table usually needs to be added with " "QTableWidget::item { padding:1px; }QTableWidget { gridline-color: #303030; }"

            class CustomDelegate : public QStyledItemDelegate
            {
            public:
                CustomDelegate(QObject* parent = nullptr) : QStyledItemDelegate(parent) {}
                void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override
                {
                    painter->setPen(QColor(0x303030));
                    if (index.row() == 0)
                        painter->drawLine(option.rect.topLeft(), option.rect.topRight());
                    if (index.column() == 0)
                        painter->drawLine(option.rect.topLeft(), option.rect.bottomLeft());
                    QStyledItemDelegate::paint(painter, option, index);
                }
            };
            
            1 Reply Last reply
            1

            • Login

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