如何在 QMdiArea 中显示 QWindow

Posted

技术标签:

【中文标题】如何在 QMdiArea 中显示 QWindow【英文标题】:How to show QWindow inside QMdiArea 【发布时间】:2021-06-09 11:46:55 【问题描述】:

我有一个继承 QWindow 和 QOpenGLFunctions_3_3_Core 的 OpenGLWindow 类,它正在打开 collada dae 文件(在简单项目中工作正常)。

我还有一个继承自 QWidgets 的 pdfViewer 类。

我想在 MdiArea 类中显示这个窗口:

void MainViewer::CreateSubWindow(QString &pathToFile)

    if (pathToFile.endsWith(".pdf"))
    
        PdfViewer *newViewer=new PdfViewer(&pathToFile);
        m_LoadedFiles->insert(pathToFile,newViewer);//this qhash save inform of current opened docs, i need it
        m_MainMdiArea->addSubWindow(static_cast<PdfViewer*>(m_LoadedFiles->value(pathToFile)))->show();
    
    if (pathToFile.endsWith(".dae"))
    
        DaeViewer *newViewer=new DaeViewer(pathToFile);
        m_LoadedFiles->insert(pathToFile, newViewer);
        m_MainMdiArea->addSubWindow(m_LoadedFiles->value(pathToFile))->show();
        static_cast<DaeViewer*>(m_LoadedFiles->value(pathToFile))->OpenGLWindow::show();
        newViewer->setAnimating(true);
    
    mdiSubWindowsCount++;

得到相同的结果:

我知道 QWidget 和 QWindow 的显示方法是不同的。

我想在 myMdiArea 中查看我的 openGlWindow 但不知道如何调用 show 方法

【问题讨论】:

【参考方案1】:

解决方案:

DaeViewer *newViewer=new DaeViewer(pathToFile);
m_MainMdiArea->addSubWindow(QWidget::createWindowContainer(newViewer))->show();

【讨论】:

以上是关于如何在 QMdiArea 中显示 QWindow的主要内容,如果未能解决你的问题,请参考以下文章