Resizing QTableWidget Columns and Rows to Fill Table

I have a QTableWidget with an N number of columns, which when the number of columns are set, they automically fill in the entire QTableWidget. When I try to dynamically change the number of columns to N/2 columns, the size of each column does not change. This results in the right half the QTableWidget being nothing but whitespace.

Conversly, if I were it reset the column count to 2*N, the column widths adjust themselves appropriately and fill the QTableWidget.

I'm wondering how I can reset the number of columns and row without the QTableWidget having any whitespace?

Answers


Have you tried setting the QHeaderView's Resize Mode?

    QTableWidget* myTable = new QTableWidet;
    QHeaderView* header = myTable->horizontalHeader();
    header->setResizeMode(QHeaderView::Stretch);

Edit: As pointed out, in Qt 5:

    QTableWidget* myTable = new QTableWidet;
    QHeaderView* header = myTable->horizontalHeader();
    header->setSectionResizeMode(QHeaderView::Stretch);

Need Your Help

const vs constexpr on variables

c++ variables c++11 const constexpr

Is there a difference between the following definitions?

Logging in delayed_job?

ruby-on-rails ruby logging delayed-job clockwork

I can't get any log output from delayed_job, and I'm not sure my jobs are starting.