When I create a new project in Qt, Qt use QQmlApplicationEngine to load qml file, rootObject in qml file is Window, like :
Window {
id: root
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Component.onCompleted: {
root.showFullScreen()
}
}
And I can use method showFullScreen to display it full my screen (full my monitor)
But, if I use QQuickView to show qml file, I can't make it full screen, I don't find any function with the same, I use like that:
QQuickView view;
view.setSource(QUrl("qrc:/main.qml"));
view.setWindowState(Qt::WindowFullScreen);
view.setResizeMode(QQuickView::SizeRootObjectToView); //even when i call this method, it doesn't still work
view.show();
qml file with this case:
Rectangle{
// rectangle has with, hight, it still doesn't work
color: "green"
}
Please guide me how to display full screen with QQuickView ? Thanks so much, I appreciate with any help !
In my opinion, there's no much difference setting main window to full-screen for
QQuickView. It inheritsQWindowand also hasshowFullScreenmethod. Therefore you can invoke this method fromc++instead of yourview.show();. If, on the other hand, you need to switch to full-screen from QML then you have to expose yourQQuickViewobject to QML, as described here:Here's also the code of
main.qmlfor reference: