سؤال

I am newer for coding andorid apps with Qt5.2 using qml,

I want to get a fullscreen app back ground Rectangle with different android device:

Rectangle {
    id:fullscreenbackground
    height: ?
    width: ?     
    ......
}

It seems height or width should been defined explicit and can't use percentage to define.

هل كانت مفيدة؟

المحلول

To resize the top-level item to the view’s size, use QQuickView::setResizeMode():

view.setResizeMode(QQuickView::SizeRootObjectToView);

That overrides any width/height set on the top-level QML item. For non-top-level items use

anchors.fill: parent

On Android, setting the resize mode should suffice. On other platforms, you might have to explicitely show the view in fullscreen:

view.showFullscreen();

نصائح أخرى

What about doing it like this:

Rectangle {
    id:fullscreenbackground
    anchors.fill: parent
    ......
}

A simple one is here!

import QtQuick 2.5
import QtQuick.Controls 1.3
import QtQuick.Window 2.0

ApplicationWindow {
    id: root
    width: Screen.width
    height: Screen.height
    color: "black"
    flags: Qt.FramelessWindowHint

    Rectangle{
        id: fullScreenRectangle
        width: Screen.width
        height: Screen.height
        border.color: "red"
        border.width: 53
        z: 1
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top