2

If QWidget is created without a parent, it creates a window.

So, when exactly is the window created? Is it when the show() is called? Or when the object is constructed?

BЈовић
  • 62,405
  • 41
  • 173
  • 273

1 Answers1

1

Window is created when the show() method is called. If you set widget's parent before showing a widget, no window is created.

Pavel Strakhov
  • 39,123
  • 5
  • 88
  • 127
  • That was my understanding as well, but do you have a link that explains that? Accessing window's id before calling show works fine. – BЈовић Apr 19 '12 at 13:06
  • As QWidget::winId documentation says, "If a widget is non-native (alien) and winId() is invoked on it, that widget will be provided a native handle." I think window id for invisible widget is created when you call winId(). – Pavel Strakhov Apr 19 '12 at 16:16
  • But it is not possible to get window's Id, without creating a window first. It can happen that a window is created in the constructor (using XCreateWindow), and then that it is shown when show() is called using XMapWindow. – BЈовић Apr 19 '12 at 16:21