Is it possible to create an Item (qml) with its own Window?
-
wrote on 3 Dec 2020, 13:54 last edited by
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. -
wrote on 3 Dec 2020, 15:52 last edited by
The problem with Window is that it is no managed by the Layouts inside the parent window. It is an independent window.
-
The problem with Window is that it is no managed by the Layouts inside the parent window. It is an independent window.
@mnesarco So what exactly do you want ?
The look of a separated window, but fixed inside the layout of an other qml component ?
-
wrote on 3 Dec 2020, 16:03 last edited by
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.
-
wrote on 3 Dec 2020, 23:32 last edited by
@mnesarco said in Is it possible to create an Item (qml) with its own Window?:
Item that have its own native Window
What is the driver behind this?
-
wrote on 4 Dec 2020, 02:06 last edited by
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 { .... } }
wrote on 4 Dec 2020, 09:43 last edited by@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
mapToItem
function fromItem
?On the main topic, did you consider using a custom
QQuickItem
to 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
mapToItem
function fromItem
?On the main topic, did you consider using a custom
QQuickItem
to integrate your external content? I don't know how feasible it would be but there are hooks to insert your own scene graph content.wrote on 4 Dec 2020, 13:44 last edited by@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.