Qt Quick 예제 - 위젯에 임베드하기

QWidget::createWindowContainer()를 통해 QWidget UI에 QQuickWindow 를 임베드하는 방법을 보여줍니다.

이 예는 QWidget 기반 애플리케이션에 Qt Quick 콘텐츠를 추가하는 접근 방식 중 하나를 보여줍니다. QQuickView 와 그 부모 클래스인 QQuickWindowQWindow 에서 파생됩니다. 즉, 다른 QWindow 과 마찬가지로 QWidget::createWindowContainer()와 함께 사용할 수 있습니다.

예제 실행하기

에서 예제를 실행하려면 Qt Creator에서 예제를 실행하려면 Welcome 모드를 열고 Examples 에서 예제를 선택합니다. 자세한 내용은 예제 빌드 및 실행하기를 참조하세요.

창을 내부에 임베드하면 위젯 계층 구조 내에 기본 자식 위젯이 생성되고 창(예제에서는 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);
}

container초기화 중 핵심 단계는 QQuickView 을 래핑하고 호스팅하는 QWidget 을 생성하는 것입니다. 그런 다음 이 위젯을 다른 QWidget 과 같은 레이아웃에 추가할 수 있습니다.

참고: 네이티브 창 임베딩을 사용하는 것은 QWidgetQt Quick 사용자 인터페이스를 결합하는 한 가지 가능한 접근 방식일 뿐입니다. 더 일반적으로 사용되는 다른 접근 방식은 QQuickWidget 입니다. QQuickWidget 을 사용하는 예는 Qt Quick 위젯 예시를 참조하세요. QQuickWidget 는 기본 창을 전혀 사용하지 않고 Qt Quick 렌더링을 텍스처로 리디렉션한 다음 OpenGL 또는 Vulkan과 같은 3D 그래픽 API를 통해 나머지 QWidget 콘텐츠와 합성하는 방식으로 렌더링과 이벤트 처리에 있어 내부적으로 상당한 차이가 있습니다. 이렇게 하면 성능이 저하되는 대신 유연성이 향상됩니다. 또한 실제 창 시스템이 없고 기본 창 개념이 없는 플랫폼에서도 작동합니다. 이 예제에서 보여주는 창 임베딩 방식은 성능이 더 우수할 수 있지만 Qt Quick 콘텐츠가 고정된 직사각형 영역을 차지하고 나중에 크기 조정, 스택 또는 클리핑되지 않는 사용자 인터페이스에 가장 적합합니다.

예제 프로젝트 @ code.qt.io

QWidget::createWindowContainer()도 참조하세요 .

© 2025 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.