Is it possible to create an Item (qml) with its own Window?
-
Hi Friends,
I want to create a QuickItem to embed some external content, but i need a Window. As far as I know, all the qml scene share the same window. In my case I need my own window but i need it to play well with layouts. I need someting like QtQuick.Window but embedded as a normal Item in the scene.Do you think it is possible?
Thanks,
Frank. -
Hi Friends,
I want to create a QuickItem to embed some external content, but i need a Window. As far as I know, all the qml scene share the same window. In my case I need my own window but i need it to play well with layouts. I need someting like QtQuick.Window but embedded as a normal Item in the scene.Do you think it is possible?
Thanks,
Frank. -
The problem with Window is that it is no managed by the Layouts inside the parent window. It is an independent window.
-
What I want is an Item that have its own native Window, but looks and behave like any other Item (ie like a Rectangle) so it can be layed out like any other component. Noboby needs to know that it is actually another window.
I managed to do that creating an Item with a nested frameless window and connecting Item's x,y,width,height with the window. It works but I wonder if is there a better way.
-
I am using opengl backend.
This is my current solution:// WindowItem.qml import QtQuick import QtQuick.Window import QtQuick.Controls Item { id: root default property alias data: wnd.data property int globalX: { var p = parent; var v = Window.window.x + x; while (p) { if (p.x) { v += p.x; } if (p.contentItem != null) { v += p.contentItem.x; } p = p.parent; } return v; } property int globalY: { var p = parent; var v = Window.window.y + y; while (p) { if (p.y) { v += p.y; } if (p.contentItem != null) { v += p.contentItem.y; } p = p.parent; } return v; } property int flags: Qt.WindowStaysOnBottomHint Window { id: wnd flags: Qt.Tool | Qt.FramelessWindowHint | root.flags x: root.globalX y: root.globalY width: root.width height: root.height visible: true } }It can be used inside the scene and play well with layouts:
Row { Label { ... } WindowItem { .... } } -
I am using opengl backend.
This is my current solution:// WindowItem.qml import QtQuick import QtQuick.Window import QtQuick.Controls Item { id: root default property alias data: wnd.data property int globalX: { var p = parent; var v = Window.window.x + x; while (p) { if (p.x) { v += p.x; } if (p.contentItem != null) { v += p.contentItem.x; } p = p.parent; } return v; } property int globalY: { var p = parent; var v = Window.window.y + y; while (p) { if (p.y) { v += p.y; } if (p.contentItem != null) { v += p.contentItem.y; } p = p.parent; } return v; } property int flags: Qt.WindowStaysOnBottomHint Window { id: wnd flags: Qt.Tool | Qt.FramelessWindowHint | root.flags x: root.globalX y: root.globalY width: root.width height: root.height visible: true } }It can be used inside the scene and play well with layouts:
Row { Label { ... } WindowItem { .... } }@mnesarco it's kind of a secondary point but I wondered if you might be able to save some of that work you are doing with coordinate mapping by using the
mapToItemfunction fromItem?On the main topic, did you consider using a custom
QQuickItemto integrate your external content? I don't know how feasible it would be but there are hooks to insert your own scene graph content. -
@mnesarco it's kind of a secondary point but I wondered if you might be able to save some of that work you are doing with coordinate mapping by using the
mapToItemfunction fromItem?On the main topic, did you consider using a custom
QQuickItemto integrate your external content? I don't know how feasible it would be but there are hooks to insert your own scene graph content.@Bob64 I have used mapToGlobal with bad results, so I resorted to manual parent position calculation. I have to try mapToItem, the main problem is that those functions do not take into account the size of the Menubar in the window. And because the Window is a top level window, at the end, I need to add Window's position too.
I have my own QQuickItem in C++, the problem is that the external renderer (OpenCascade/opengl) uses the whole window and I cannot change that. So I need to provide a different window because if not it renders under the whole schene.