--- a/src/main.cpp Tue Jun 28 14:24:00 2022 +0300 +++ b/src/main.cpp Tue Jun 28 14:53:22 2022 +0300 @@ -28,7 +28,7 @@ Q_OBJECT public: const ModelId modelId; - ModelSubWindow(ModelId modelId, QWidget* widget) : + explicit ModelSubWindow(ModelId modelId, QWidget* widget = nullptr) : QMdiSubWindow{widget}, modelId{modelId} { @@ -400,6 +400,19 @@ dialog.exec(); } +template<class SubWindow, class... Args> +SubWindow* createSubWindow(QMdiArea* mdiArea, Args&&... args) +{ + // Qt seems to have a bug where the first created sub window does not render + // properly until it is minimized and maximized again. This only happens + // if we give the mdi area as a parent argument. As a work-around, we create + // the sub window with parent=nullptr, and add it manually. + // c.f. https://bugreports.qt.io/browse/QTBUG-69495 + SubWindow* subWindow = new SubWindow{args..., nullptr}; + mdiArea->addSubWindow(subWindow); + return subWindow; +} + int main(int argc, char *argv[]) { doQtRegistrations(); @@ -568,8 +581,9 @@ }); QObject::connect(data->canvas.get(), &PartRenderer::message, &messageLog, &MessageLog::addMessage); const QFileInfo fileInfo{*documents.modelPath(modelId)}; - ModelSubWindow* subWindow = new ModelSubWindow{modelId, ui.mdiArea}; + auto* const subWindow = createSubWindow<ModelSubWindow>(ui.mdiArea, modelId); subWindow->setMinimumSize({96, 96}); + subWindow->resize({320, 200}); subWindow->setWidget(data->canvas.get()); subWindow->setWindowTitle(tabName(fileInfo)); subWindow->show(); @@ -591,7 +605,7 @@ }); QObject::connect(ui.actionSettingsEditor, &QAction::triggered, [&]{ if (ui.mdiArea->findChildren<SettingsEditor*>().isEmpty()) { - SettingsEditor* settingsEditor = new SettingsEditor{defaultKeyboardShortcuts, ui.mdiArea}; + auto* const settingsEditor = createSubWindow<SettingsEditor>(ui.mdiArea, defaultKeyboardShortcuts); QObject::connect(&settingsChanged, &Signal::triggered, settingsEditor, &SettingsEditor::loadSettings); QObject::connect(settingsEditor, &SettingsEditor::settingsChanged, restoreSettings); settingsEditor->setAttribute(Qt::WA_DeleteOnClose);