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. QTableWidget headers stretching past size of borders
Forum Updated to NodeBB v4.3 + New Features

QTableWidget headers stretching past size of borders

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 241 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.
  • Dummie1138D Offline
    Dummie1138D Offline
    Dummie1138
    wrote on last edited by
    #1

    Hi. I have a QTableWidget where the headers are stretching past the size of the borders.

    This is the code I have used to configure the headers.

        ui->tableWidget_Configs->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
        ui->tableWidget_Configs->setColumnWidth(0, 1);   //Yes, the size of this column is 1px. This was for a test.
        ui->tableWidget_Configs->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
        ui->tableWidget_Configs->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
        ui->tableWidget_Configs->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch);
    

    And this is what the headers look like.

    028ced59-e059-4dc6-a3d8-ca00b5f66d44-image.png

    08b4f0b2-cddd-470b-b3f2-ee607832de71-image.png

    I am unsure why the headers would possibly expand beyond the borders. Please let me know if more information is required.

    Christian EhrlicherC 1 Reply Last reply
    0
    • Dummie1138D Dummie1138

      Hi. I have a QTableWidget where the headers are stretching past the size of the borders.

      This is the code I have used to configure the headers.

          ui->tableWidget_Configs->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
          ui->tableWidget_Configs->setColumnWidth(0, 1);   //Yes, the size of this column is 1px. This was for a test.
          ui->tableWidget_Configs->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
          ui->tableWidget_Configs->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
          ui->tableWidget_Configs->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch);
      

      And this is what the headers look like.

      028ced59-e059-4dc6-a3d8-ca00b5f66d44-image.png

      08b4f0b2-cddd-470b-b3f2-ee607832de71-image.png

      I am unsure why the headers would possibly expand beyond the borders. Please let me know if more information is required.

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Dummie1138 said in QTableWidget headers stretching past size of borders:

      ui->tableWidget_Configs->setColumnWidth(0, 1);

      I would guess this does not work because of https://doc.qt.io/qt-6/qheaderview.html#minimumSectionSize-prop

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Dummie1138D 1 Reply Last reply
      4
      • Christian EhrlicherC Christian Ehrlicher

        @Dummie1138 said in QTableWidget headers stretching past size of borders:

        ui->tableWidget_Configs->setColumnWidth(0, 1);

        I would guess this does not work because of https://doc.qt.io/qt-6/qheaderview.html#minimumSectionSize-prop

        Dummie1138D Offline
        Dummie1138D Offline
        Dummie1138
        wrote on last edited by
        #3

        @Christian-Ehrlicher This did also fix the issue, thanks.

        1 Reply Last reply
        0

        • Login

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