This is quite odd.
Using this code, I am attempting to add a tab to a QTabWidget:
void SideWidget::changePanel(SearchablePanel* panel){
ui->nextButton->setEnabled(false);
cout << pointer;
widgetHistory[++pointer] = panel;
QWidget* widget = panel->getWidget();
cout << panel->id;
MainWindow::main->addTab(widget, "nT");
QTextEdit* thing = new QTextEdit("Test");
MainWindow::main->addTab(thing, "tabqx");
this->internalChange(panel);
}
And internalChange:
void SideWidget::internalChange(SearchablePanel *panel){
cout << "internale change, "+panel->id;
ui->scrollPanel->setWidget(panel->getWidget());
ui->prevButton->setEnabled(true);
}
Now, when I add the tab “tabqx” it works, and when I set the scrollPanel’s widget to panel->getWidget() it works. However, when I attempt to add the tab “nT”, it does not work. I am very confused. I should note that panel->getWidget() returns a QWidget, as might be expected. In this instance specifically, it will return a QTextEdit. Also, MainWindow::main is a static QTabWidget.
So my question is, why is the tab “nT” not being added?
Basically your code does that:
And since a widget can only be at one place at a time, once you add it to the scroll panel, it is removed from the
QTabWidgetwhere you just put it.However you could create a new
QTextEditthat would share the same underlyingQTextDocumentby using QTextEdit::document()/setDocument().