[Interest] QOpenGLWindow inside QSplitter horizontal layout ?
Volker Hilsheimer
volker.hilsheimer at qt.io
Fri May 21 09:38:59 CEST 2021
> On 21 May 2021, at 06:02, Nicholas Yue <yue.nicholas at gmail.com> wrote:
>
> Hi,
>
> I am learning about QOpenGLWindow
>
> I saw examples which utilizes it via
>
> QWidget::createWindowContainer()
>
> I am wondering if there is a way to house it as a widget inside a layout ?
>
> My current attempt is not working.
>
> ```
> MainWindow::MainWindow(QWidget *parent) :
> QMainWindow(parent),
> ui(new Ui::MainWindow),
> m_myWindow(new MyOpenGLWindow)
> {
> ui->setupUi(this);
>
> connect(ui->actionQuit, &QAction::triggered, this, &MainWindow::OnFileClose);
>
> m_myWindow->create();
> #ifdef ORIGINAL_WORKING_EXAMPLE
> m_myWindow->setMainWindow(this);
> QWidget *w = QWidget::createWindowContainer(m_myWindow);
>
> takeCentralWidget();
> setCentralWidget(w);
> #else
> m_myWindow->setMainWindow(this);
> QWidget *w = QWidget::createWindowContainer(m_myWindow);
> // delete ui->targetWidget;
> // ui->targetWidget = QWidget::createWindowContainer(m_myWindow);
> // ui->targetWidget->setMinimumSize(400,400);
> w->setMinimumSize(200,200);
> w->setMaximumSize(200,200);
> // ui->targetWidget->createWindowContainer(m_myWindow);
> // takeCentralWidget();
> //setCentralWidget(ui->targetWidget);
> ui->splitter->layout()->addWidget(w);
> #endif
> }
> ```
>
> Cheers
> --
> Nicholas Yue
As the name suggests, QOpenGLWindow is a QWindow, and QWindow’s are designed to be top level windows.
To embed an OpenGL rendering surface into a widget-based UI, you should be looking at QOpenGLWidget instead:
https://doc.qt.io/qt-6/qopenglwidget.html
Volker
More information about the Interest
mailing list