Qt Quick 예제 - 위젯에 삽입하기
QWidget::createWindowContainer()를 통해 QQuickWindow 를 QWidget UI에 삽입하는 방법을 보여줍니다.

이 예제는 Qt Quick 콘텐츠를 QWidget 기반 애플리케이션에 추가하는 방법 중 하나를 보여줍니다. QQuickView 와 그 상위 클래스인 QQuickWindow 는 QWindow 에서 파생됩니다. 즉, 다른 QWindow 와 마찬가지로 QWidget::createWindowContainer()와 함께 사용할 수 있습니다.
예제 실행
다음에서 예제를 실행할 수 있습니다:
- Qt Creator
Welcome 모드를 열고 Examples 에서 예제를 선택하십시오. 자세한 내용은 Qt Creator: 튜토리얼: 빌드 및 실행을 참조하십시오.
- Qt Extension for Visual Studio Code
Command Palette 에서 Qt: Open Qt examples 명령을 실행하고 목록에서 예제를 선택합니다. 자세한 내용은 Qt Extension for Visual Studio Code: 튜토리얼: 빌드 및 실행을 참조하십시오.
창을 내부적으로 삽입하면 위젯 계층 구조 내에 네이티브 자식 위젯이 생성되며, 창(이 예제의 경우 QQuickView )의 부모가 변경됩니다. 컨테이너 위젯은 자식 창의 위치를 재조정하여, 실제로는 부모인 QWidget 기반 최상위 창과 독립적으로 렌더링되는 별도의 네이티브 창임에도 불구하고 사용자 인터페이스의 일부처럼 보이도록 처리합니다.
MainWindow::MainWindow()
: m_quickView(new QQuickView)
{
QWidget *centralWidget = new QWidget(this);
QVBoxLayout *layout = new QVBoxLayout(centralWidget);
m_quickView->setResizeMode(QQuickView::SizeRootObjectToView);
connect(m_quickView, &QQuickView::statusChanged,
this, &MainWindow::quickViewStatusChanged);
connect(m_quickView, &QQuickWindow::sceneGraphError,
this, &MainWindow::sceneGraphError);
m_quickView->loadFromModule("embeddedinwidgets", "Main");
QWidget *container = QWidget::createWindowContainer(m_quickView);
container->setMinimumSize(m_quickView->size());
container->setFocusPolicy(Qt::TabFocus);
layout->addWidget(new QLineEdit(QStringLiteral("A QLineEdit")));
layout->addWidget(container);
layout->addWidget(new QLineEdit(QStringLiteral("A QLineEdit")));
setCentralWidget(centralWidget);
QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(tr("Quit"), qApp, &QCoreApplication::quit);
}초기화 과정에서 핵심 단계는 QQuickView 를 감싸고 호스팅하는 QWidget 인 container 를 생성하는 것입니다. 이 위젯은 다른 QWidget 와 마찬가지로 레이아웃에 추가될 수 있습니다.
참고: 네이티브 창 임베딩을사용하는 것은 QWidget 와 Qt Quick 사용자 인터페이스를 결합하는 한 가지 가능한 접근 방식일 뿐입니다. 이를 위한 또 다른, 더 일반적으로 사용되는 접근 방식은 QQuickWidget 입니다. QQuickWidget 사용 예시는 Qt Quick 위젯 예제를 참조하십시오. 렌더링 및 이벤트 처리 측면에서 내부적으로 상당한 차이가 있습니다. QQuickWidget 는 네이티브 윈도우를 전혀 사용하지 않으며, Qt Quick 의 렌더링 결과를 텍스처로 리디렉션한 후, OpenGL이나 Vulkan과 같은 3D 그래픽 API를 통해 QWidget 의 나머지 콘텐츠와 합성합니다. 이는 성능을 희생하는 대신 더 큰 유연성을 제공합니다. 또한 실제 윈도우 시스템이 없고 네이티브 윈도우 개념이 없는 플랫폼에서도 작동합니다. 반면, 이 예제에서 시연한 윈도우 임베딩 방식은 더 높은 성능을 낼 수 있지만, Qt Quick 콘텐츠가 고정된 직사각형 영역을 차지하고 이후 크기가 조정되거나 겹치거나 잘리지 않는 사용자 인터페이스에 가장 적합합니다.
QWidget::createWindowContainer()도 참조하십시오 .
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.