I have a QTableView and some content in it. I want a behavior like horizontalHeader() -> setResizeMode( ResizeToContent ) but it must not create horizontal scrollbars – I mean the viewport must not be wider than the table.
Even with creating a new QHeaderView it’s not so easy, since there are only a few virtual methods.

Thanks in advance,
Charly
PS: I have a custom item delegate, which shortens the long texts with “…”. It returns as sizeHint() the full size, but when the paint() method receives a smaller size (e.g. simulated with resizeMode() == Qt::Interactive) it crops the content.
New Answer
You need to set the stretch on individual sections, I’ve created a simple test app:
test.cpp
test.pro
Notice: It’s important that
void QHeaderView::setResizeMode(int, ResizeMode)is called when when this logical index exists, that is, when a model which defines these columns is attached to the view.Old Answer
QAbstractScrollArea has the horizontalScrollBarPolicy property which can have the option
ScrollBarAlwaysOff.Try something like: