0

When I use Qt Widget to build GUI, I can add a QWidget(sub window) in a QMainWindow(main window):

auto* wrapper = QWidget::createWindowContainer(m_window, this);
ui->horizontalLayout->addWidget(wrapper);
ui->centralWidget->setLayout(ui->horizontalLayout);

My application need the winId of a sub window. Now I am trying to using QML to build GUI.

ApplicationWindow {
    id: window
    width: 800
    height: 600
    visible: true

    menuBar: MenuBar {
    }
}

Is there any way to add a window(can invoke winId()) to the ApplicationWindow?

I tried to add Window in QML while two separate windows will appear, what I want is to have only one window, with sub window inside the main window.

liuyulvv
  • 154
  • 10
  • I don't need `winId` of `ApplicationWindow`, I need a winId to show the result of my rendering system, if I use the `winId` of `ApplicationWindow` or `main window`, the entire window will be my render result. I need a `sub window` and show rendering in the `sub window`. It is different from [this](https://stackoverflow.com/questions/42490280/qml-get-the-winid-of-a-loaded-qml-window). – liuyulvv Apr 27 '23 at 14:24

1 Answers1

0

Although the reason of requirement of sub window is not clear for me(since the solution may depend on it), you could do it in C++ by following:

  • Create a custom class inherits QQuickView,
  • Expose it to QML using qmlRegisterType
  • Instantiate it as a child element of ApplicationWindow

Here, since QQuickView is derived from QWindow, you'll be able to access its winId in C++. Also, if you want to access ApplicationWindow winId, it will be required to expose it to C++ side.

dynerp
  • 76
  • 6