简体   繁体   中英

sizing a qml qquickview inside its window container

I have a QQuickView inside another widget using createWindowContainer() (see image below). The QML scene file of the QQuickView looks something like:

//import related modules
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Window 2.2
import QtMultimedia 5.6

Rectangle {
    width: 200
    height: 100
    color: "red"
    ...
}

I can see the qml object in the QQuickView, but what I'd really like is to be able to resize the QML scene to fit the container. I've looked at various docs and haven't found a way to reference the container in the QML scene to properly resize. Is that possible? Something like this?

Rectange {
    width: Container.width
    height: Container.height
}

红色的QML场景

Just remove size setting and add anchors.fill: parent to the Rectangle. Another way is to set view->setResizeMode(QQuickView::SizeRootObjectToView); in C++

Using the solution folibis provided works great (the first one).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM