I am trying to add a tab to an existing QTabWidget. I laid out the tab in QT Designer with one existing tab. I then programmatically added a tab. Visually, the first tab almost completely disappears as the new tab overlaps it. If I try to click on the original tab, it completely disappears and is replaced by the new tab. Adding additional tabs work fine, except that the original tab is still gone.
I tried removing the QT designer from the equation and just copied the code. I still have the same problem. Here is what my code now looks like:
outputLogGroupBox is a QGroupBox *
static QTabWidget *diagnosticsTabWidget;
diagnosticsTabWidget = new QTabWidget(m_qUI.outputLogGroupBox);
diagnosticsTabWidget->setObjectName(QStringLiteral("diagnosticTabWidget"));
diagnosticsTabWidget->setGeometry(QRect(16, 79, 421, 551));
QWidget * outputTab = new QWidget();
outputTab->setObjectName(QStringLiteral("Output"));
diagnosticsTabWidget->addTab(outputTab, QString());
diagnosticsTabWidget->setTabText(diagnosticsTabWidget->indexOf(outputTab), QStringLiteral("Output"));
diagnosticsTabWidget->setCurrentIndex(0);
diagnosticsTabWidget->setHidden(false);
QWidget * newTab = new QWidget();
diagnosticsTabWidget->addTab(newTab, "test");
If I leave out the creation of newTab, I see my original tab (outputTab) fine. With the creation of the second tab, I see one tab with part of the name of the original tab (output) and the name of the second tab (test). If I add a third tab, I get the same as with the second tab, except with the third tab. Clicking on any of the tab displays what looks like a proper set of tabs, with the original tab missing.
diagnosticsTabWidget
without a parent -- so justdiagnosticsTabWidget = new QTabWidget;
. Not sure if that's significant in this case. Also, given that you do givediagnosticsTabWidget
a parent you might want to remove the call tosetGeometry
to see what effect that has (if any). – G.M.