2

I have a WindowID where I want to embed a QMainWindow.

Briefly summarized: I'm finding the equivalent of gtk.gdk.window_foreign_new().

My not working Qt5.2 code is:

WId nonqt_window_id = WId(0x7A00516);

QWindow* nonqt_parent_window = QWindow::fromWinId(nonqt_window_id);
QWidget* parent_widget = QWidget::createWindowContainer(nonqt_parent_window);

this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint);
this->setParent(nonqt_parent_window);

Notes

  • this code has been written into the constructor of the QMainWindow
  • and I got the desired parent window into nonqt_parent_window variable
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
andras.tim
  • 1,964
  • 1
  • 13
  • 23
  • I want to create an `xscreensaver` app, what can be run embed and standalone too. The xscreensaver framework provides the WindowID, where I can embed my windows (what the `gtk.gdk.window_foreign_new()` can do in C++, or Python), but I don't know how can I reparent a Qt (main) window to a non Qt window. – andras.tim Aug 01 '17 at 17:44
  • Just realized that you may have your own process with the only widget (simple QWidget) reparented. Why QMainWindow? – Alexander V Aug 01 '17 at 19:07
  • @AlexanderVX I thought the `QMainWindow` will be useful for my problem. Because when I run the binary directly, I would like to show a standard window. But when the `xscreensaver` runs my app I want to embed my stuff into the got WindowID. – andras.tim Aug 01 '17 at 20:38
  • Do you prefer to I create the business logic in a `QWidget` and embed it, and in standalone mode, I use the `QWidget` in my `QMainWindow`? – andras.tim Aug 01 '17 at 20:40
  • Yep, make some re-parentable QWidget. Or whatever not QMainWindow-derived. QMainWindow wants a bit too much in terms of being app main window e.g. task entry (I cannot recall all) and also needs to be on its own. – Alexander V Aug 01 '17 at 20:43
  • In other hands, I think my current code does the opposite what I want. Because the original content of `noqt_parent_window` is moved to my `QMainWindow`. But I don't know why? – andras.tim Aug 01 '17 at 20:46
  • That QMainWindow still behaves main window. You need an embeddable widget. You can even do the whole app with QWidget being main window and just make sure you provide correct attributes for it to be embedded. Oh... details. – Alexander V Aug 01 '17 at 21:07

0 Answers0