Important: Please read the Qt Code of Conduct -

Fit QTableWidget headers

  • 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));

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

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

    But I want to find Qt-Way.

  • 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.

Log in to reply