Releasing and restoring an embedded window in Qt

727 Views Asked by At

In my Qt application, I need to embed a native window. I start by obtaining it's WinId. After that, I create the embedded widget in the following way:

QWindow * window = new QWindow::fromWinId(winid);
QWidget * widget = createWindowContainer(window);
QVBoxLayout vl;
ui->frame->setLayout(&vl);
vl.addwidget(widget);
widget->show();

It works perfectly in the way it is meant to be. However, I am facing problems when I want to shut down my Qt application and release and restore the embedded window to its original state.

I am currently doing the following steps in releasing the window:

QWindow * releasedWindow = new QWindow();
window->setParent(newWin);
newWin->show();

It works in a way, but not like I want it to be. If I do this, the released window retains the resolution and geometry that it had while it was embedded, which differs from what they were natively. It also does not respond to resizing the window. The released window also loses its menu bar.

I want it to be restored into the original state that it had before the embedding. Is there a way to achieve that?

I'm using Qt 5.5 with Windows 7.

1

There are 1 best solutions below

0
On BEST ANSWER

It seems that I found a solution already. Releasing the window by simply

window->setParent(nullptr);
window->setFlags(Qt::Window);

Does the trick.