1

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:

  • making sizehintrole in headerData in my model and return my own size;
  • changing setSectionResizeMode to ResizeToContent
  • setting every column's width with and without resize modes through "setColumnWidth"
  • making my own delegate with sizehint overloading with my wanted size
  • setting stylesheet with padding 0px; to QTableView, QTableView::section, QTableView::item
  • using "header->setDefaultSectionSize"

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Greadimar
  • 81
  • 8
  • Can you reduce the size of the `QTableView` itself? Perhaps set the maximum width in designer and put a horizontal expanding spacer next to it. – drescherjm Dec 13 '19 at 12:31
  • Spacer is already there, and reducing the size of tableview will just cut the cells @drescherjm – Greadimar Dec 13 '19 at 12:34

1 Answers1

1

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

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

(Docs here).

p-a-o-l-o
  • 9,807
  • 2
  • 22
  • 35