It certainly looks like the layout containing the "test" group box has a top margin set, so I would definitely check that again carefully. And then check it again :)
Could you possibly have set the font for the "test" group box to some font type or size that may be throwing things off?
Are you applying a style sheet that may be affecting things?
Edit:
I've included the .ui and resulting code in .h from my experiment with the layouts you describe as requested in comments.
mainwindow.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>376</width>
<height>433</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>GroupBox</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QWidget" name="widget" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>GroupBox</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QWidget" name="widget_2" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>376</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
..interesting part of ui_mainwindow.h
public:
QWidget *centralWidget;
QGridLayout *gridLayout;
QGroupBox *groupBox;
QWidget *widget;
QGridLayout *gridLayout_2;
QGroupBox *groupBox_2;
QWidget *widget_2;
QMenuBar *menuBar;
QToolBar *mainToolBar;
QStatusBar *statusBar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(376, 433);
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
gridLayout = new QGridLayout(centralWidget);
gridLayout->setSpacing(0);
gridLayout->setContentsMargins(0, 0, 0, 0);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
groupBox = new QGroupBox(centralWidget);
groupBox->setObjectName(QString::fromUtf8("groupBox"));
groupBox->setFlat(false);
gridLayout->addWidget(groupBox, 0, 0, 1, 1);
widget = new QWidget(centralWidget);
widget->setObjectName(QString::fromUtf8("widget"));
gridLayout_2 = new QGridLayout(widget);
gridLayout_2->setSpacing(0);
gridLayout_2->setContentsMargins(0, 0, 0, 0);
gridLayout_2->setObjectName(QString::fromUtf8("gridLayout_2"));
groupBox_2 = new QGroupBox(widget);
groupBox_2->setObjectName(QString::fromUtf8("groupBox_2"));
QFont font;
font.setFamily(QString::fromUtf8("MS Shell Dlg 2"));
font.setPointSize(8);
font.setBold(false);
font.setWeight(50);
font.setKerning(true);
groupBox_2->setFont(font);
groupBox_2->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
groupBox_2->setFlat(false);
gridLayout_2->addWidget(groupBox_2, 0, 0, 1, 1);
widget_2 = new QWidget(widget);
widget_2->setObjectName(QString::fromUtf8("widget_2"));
gridLayout_2->addWidget(widget_2, 1, 0, 1, 1);
gridLayout->addWidget(widget, 0, 1, 1, 1);
MainWindow->setCentralWidget(centralWidget);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 376, 21));
MainWindow->setMenuBar(menuBar);
mainToolBar = new QToolBar(MainWindow);
mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(MainWindow);
statusBar->setObjectName(QString::fromUtf8("statusBar"));
MainWindow->setStatusBar(statusBar);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi