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. Fit QTableWidget headers
Qt 6.11 is out! See what's new in the release blog

Fit QTableWidget headers

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.1k 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.
  • T Offline
    T Offline
    tucnak
    wrote on last edited by
    #1

    Hi! I am using item-based QTableWidget. So I created some headers... Now I want to fit headers in %-age for QTableWidget width.
    @
    QStringList h;
    h << "Lorem" << "Ipsum" << "Dolor" << "Sit";
    QStringList v;
    for(int k = 'A'; k <= 'N'; k++) {
    v << QString(QChar(k));
    }
    ui->schedule->setHorizontalHeaderLabels(h);
    ui->schedule->setVerticalHeaderLabels(v);
    @

    This code leaves clear space in the right side of table. How to fit it?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tucnak
      wrote on last edited by
      #2

      I found a way using [ (width / 100) * %-age ] where sum of %-ages == 100;

      But I want to find Qt-Way.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        There is no simple Qt method to share the space niceley between columns. You might want to consider setting stretchLastSection of the [[Doc:QHeaderView]] to true. This will allocate the remaining space to the last column.

        http://www.catb.org/~esr/faqs/smart-questions.html

        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