QHeaderView: Stretch *and* ResizeToContents?
mzimmers last edited by mzimmers
Hi all -
This probably sounds weird, but I'm trying to format a QTableView so that each column's content is fully visible.
When I use ResizeToContents mode, it looks like this:
and when I use Stretch, it looks like this:
I could use minimum column widths, I suppose, but...is there a better way to to it?
Can you show what exactly you're doing (code)?
I usually use:
To tweak the appearance of the sections, but it's hard to tell if that's what you're looking for exactly.
QSizePolicy qsp; QHeaderView *qhv; // set the size policy to expanding. qsp.setHorizontalPolicy(QSizePolicy::Expanding); qsp.setVerticalPolicy(QSizePolicy::Expanding); // set the table to stretch mode. qhv = ui->tableView->horizontalHeader(); qhv->setSectionResizeMode(QHeaderView::Stretch);
That's an overload that sets it uniformly to all sections. You can use the overload that takes a section number to have different behaviours between the columns.
so, ResizeToContents for the ones that tend to be wider, and stretch for the rest?
Well, yes, it's finicky, but should be enough to get it to something you like.
I think this will work:
Not beautiful, but definitely better. Thanks, kshegunov.