How to make a Qt widget invisible without changing the position of the other Qt widgets?

This problem was solved in Qt 5.2. The cute solution is:

QSizePolicy sp_retain = widget->sizePolicy();
sp_retain.setRetainSizeWhenHidden(true);
widget->setSizePolicy(sp_retain);

http://doc.qt.io/qt-5/qsizepolicy.html#setRetainSizeWhenHidden

Leave a Comment