c++qtqtableviewqheaderview

QTableView columns - can't set small width


I have two QTableView with own simple models. After making the following:

    tv1->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    tv1->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    tv1->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
    tv1->resizeColumnsToContents();

I have this picture:

enter image description here

And here what I want:

enter image description here

What I've tried:

Nothing of these works. I am desperate enough to draw the table from zero with QPainter or follow every source file to watch the real size. But before that, I would appreciate for any advice.


Solution

  • You can try setting the minimum section size to zero for the horizontal header, this way:

    tv1->horizontalHeader()->setMinimumSectionSize(0);
    

    (Docs here).