#include #include #include #include #include #include int main(int argc, char *argv[]) { QApplication a(argc, argv); auto w = new QMainWindow(); w->setMinimumSize({ 300, 300 }); w->show(); auto c = new QWidget(); auto l = new QHBoxLayout(); c->setLayout(l); w->setCentralWidget(c); auto tw1 = new QTabWidget(); l->addWidget(tw1); auto addTab = [tw1](const QString& title) { auto tab = new QWidget(tw1); tab->setStyleSheet("background-color: red"); tab->setMinimumSize({ 200, 200 }); tw1->addTab(tab, title); tab->setAttribute(Qt::WA_NativeWindow); }; addTab("tab 1"); addTab("tab 2"); addTab("tab 3"); addTab("tab 4"); auto mb = w->menuBar(); auto action = new QAction("Move to new tab widget", w); QObject::connect(action, &QAction::triggered, w, [tw1, l, c]() { auto tw2 = new QTabWidget(c); // showing the tab widget before inserting the tab prevents the issue //tw2->show(); l->addWidget(tw2); auto t1 = tw1->widget(0); tw1->removeTab(0); // reparenting before inserting prevents the issue //t1->setParent(tw2); tw2->addTab(t1, "tab"); }); mb->addAction(action); return a.exec(); }