0
votes

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.

1
I tried creating a brand new tab in qt designer. Same problem.Rachel Gold
Can't reproduce with the code shown (Linux + Qt5.11.0).G.M.
I'm using qt 5.1.0. I expect that you are using something newer. I can't believe this is a qt bug, but it is nice to know that I didn't miss something stupid with the code. I'm going to try to create a new project with just a tab widget and see what happensRachel Gold
I created a new tab widget with two tabs directly through qt designer. Even without me manually doing anything, I get the exact same problem.Rachel Gold
Actually, I did make change to the code shown. I constructed diagnosticsTabWidget without a parent -- so just diagnosticsTabWidget = new QTabWidget;. Not sure if that's significant in this case. Also, given that you do give diagnosticsTabWidget a parent you might want to remove the call to setGeometry to see what effect that has (if any).G.M.

1 Answers

0
votes

I'm an idiot.

While trying to get something else working, I mucked around with style sheets and added this:

setStyleSheet("QTabBar::tab:first {max-width: 0px;}");

Evidently, that doesn't affect things when there is only one tab, but when one adds a second...