comp1201
comp1201

Reputation: 415

Creating a new top-level QML Window using createObject (null)

I am working on a desktop application where I need the user to be able to "undock" certain elements of the GUI. I am currently achieving this by reparenting the element that needs to be undocked to the contentItem of a dynamically created ApplicationWindow. This works well but only if I pass null or undefined as the parent to the createObject() function like so:

var window_component = Qt.createComponent("Secondary_Window.qml")
var window_object = window_component.createObject(null, {section_name: section})

If I pass anything else to the createObject() function, like say the main window element or a child of the main window element, I get a window but I can not bring the main window in front of the new window by clicking on it. Nor are there tabs that appear in the Windows taskbar indicating that the application is currently using multiple Windows. The new window literally remains up front at all times until it is closed. So my question is: Is it good practice to dynamically create a new window in QML by calling window_component.createObject (null) or is there another way to achieve what I described above (by say passing a flag to the window)? I have been experimenting with different flag combinations but haven't yet found a combination that works. Also, the documentation of createObject() says that if you don't pass a parent as a parameter then the object will not be visible but that doesn't seem to be the case here. The window is displaying just fine.

Upvotes: 1

Views: 470

Answers (1)

David K. Hess
David K. Hess

Reputation: 17246

A parent is a defined concept for Items.

A Window is not an Item so specifying null is not only ok but appropriate.

Upvotes: 1

Related Questions