2

I use Python and Pyside2, I try to insert a QQuickWidget inside a Qwidget or inside a Layout but I haven't find a solution. I try with this code:

view = QQuickWidget()
view.setSource(QUrl.fromLocalFile("main.qml"))

but QQuickWidget start in another windows. I try use:

Layout.addWidget(view)

but it required a QWidget and don't work with QQuickWidget. I found this similar question (in C) but it don't work in Python: Adding QQuickWidget in QStackedWidget

I have try QQmlApplicationEngine and QQuickView, but problem is the some.

Can you help me ?

Edit: main.qml file is:

import QtQuick 2.0
import QtQuick.Window 2.0
import QtLocation 5.6
import QtPositioning 5.6

Window {
    width: 300
    height: 300
    visible: true

    Plugin {
        id: mapPlugin
        name: "esri"
    }

    Map {
        anchors.fill: parent
        plugin: mapPlugin
        center: QtPositioning.coordinate(39.2160, 9.1344)
        zoomLevel: 16
    }
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Skyfox
  • 35
  • 1
  • 7
  • show your main.qml. I think the cause of the problem is in the .qml – eyllanesc Jan 09 '19 at 20:57
  • `import QtQuick 2.0 import QtQuick.Window 2.0 import QtLocation 5.6 import QtPositioning 5.6 Window { width: 300 height: 300 visible: true Plugin { id: mapPlugin name: "esri" } Map { anchors.fill: parent plugin: mapPlugin center: QtPositioning.coordinate(39.2160, 9.1344) zoomLevel: 16 } }` – Skyfox Jan 09 '19 at 21:34
  • please edit your question and add it there – eyllanesc Jan 09 '19 at 21:34
  • I have add it in main question – Skyfox Jan 09 '19 at 21:39

1 Answers1

3

The problem is that the root element is a Window that will create a window, the solution is to use an Item:

import QtQuick 2.0
import QtLocation 5.6
import QtPositioning 5.6

Item {
    width: 300
    height: 300

    Plugin {
        id: mapPlugin
        name: "esri"
    }

    Map {
        anchors.fill: parent
        plugin: mapPlugin
        center: QtPositioning.coordinate(39.2160, 9.1344)
        zoomLevel: 16
    }
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241