Question

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?

Was it helpful?

Solution

Basically your code does that:

MainWindow::main->addTab(panel->getWidget(), "nT"); 
ui->scrollPanel->setWidget(panel->getWidget());

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 QTabWidget where you just put it.

However you could create a new QTextEdit that would share the same underlying QTextDocument by using QTextEdit::document()/setDocument().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top