In Qt 5.2 it is possible to do the following:
QSizePolicy sp_retain = widget->sizePolicy();
sp_retain.setRetainSizeWhenHidden(true);
widget->setSizePolicy(sp_retain);
I earlier posted the same solution here:
How to make a Qt widget invisible without changing the position of the other Qt widgets?
(which seems to be a duplicate of this question).