In a previous question, I was given code which shows a implementation of heightForWidth() (thanks, @Kuba Ober) that works, but it does so only for a top-level QWidget. I tried to reproduce it for a QMainWindow, but it did not work.
This is the code where heightForWidth() works for a top-level QWidget:
QWidget w;
QVBoxLayout * l = new QVBoxLayout(&w);
l->addWidget(new Widget);
w.show();
And this is where I try to implement the same for QMainWindow, but here it heightForWidth() has no effect (even though it gets called):
QMainWindow mainWnd;
QWidget *w = new QWidget;
QVBoxLayout * l = new QVBoxLayout(w);
l->addWidget(new Widget);
mainWnd.setCentralWidget(w);
// Second widget to take unused space.
QFrame * btm = new QFrame;
btm->setFrameShape(QFrame::Panel);
btm->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
l->addWidget(btm);
mainWnd.show();
So why doesn't the QMainWindow implementation work?