Try QWidget::setContentsMargins(int,int,int,int) and QLayout::setSpacing(int).