【问题标题】:How to use QtQuick.Window element in Qt5 and QML?如何在 Qt5 和 QML 中使用 QtQuick.Window 元素?
【发布时间】:2012-12-07 17:58:15
【问题描述】:

我最近为 Mac OS X 安装了 Qt5 RC2 并开始开发一些 QML 应用程序。看了新元素后,特别想试试Window和Screen Element。 (http://qt-project.org/doc/qt-5.0/qtquick/qmlmodule-qtquick-window2-qtquick-window-2.html)

所以我将导入设置在文件顶部,如下所示:

导入 QtQuick 2.0
导入 QtQuick.Window 2.0

找到了导入,但我既不能使用 Window 也不能使用 Screen。每次我键入 Screen 或 Window 时都会出现一个错误,上面写着“Unknown component (M300)”

有人知道问题出在哪里吗?

【问题讨论】:

  • Qt 5.0 在那里。用那个试过了吗?
  • 是的,我试过了。但它仍然无法正常工作。

标签: qt window qml qt5


【解决方案1】:

有时 QtCreator 无法识别某些类型/属性,主要是 Qt4.x 中不存在的类型/属性,但这并不意味着您不能使用它们,所以是的,'Window' 就像属性一样是未知的'antialiasing'、'fontSizeMode' 或 'active' 是,但你可以使用它们,这里是 QtQuick.Window 2.0 的使用示例:

import QtQuick        2.0
import QtQuick.Window 2.0

Window {
    id: win1;
    width: 320;
    height: 240;
    visible: true;
    color: "yellow";
    title: "First Window";

    Text {
        anchors.centerIn: parent;
        text: "First Window";

        Text {
            id: statusText;
            text: "second window is " + (win2.visible ? "visible" : "invisible");
            anchors.top: parent.bottom;
            anchors.horizontalCenter: parent.horizontalCenter;
        }
    }
    MouseArea {
        anchors.fill: parent;
        onClicked: { win2.visible = !win2.visible; }
    }

    Window {
        id: win2;
        width: win1.width;
        height: win1.height;
        x: win1.x + win1.width;
        y: win1.y;
        color: "green";
        title: "Second Window";

        Rectangle {
            anchors.fill: parent
            anchors.margins: 10

            Text {
                anchors.centerIn: parent
                text: "Second Window"
            }
        }
    }
}

你只需要一个 Window 项作为根对象,你可以在其中嵌入其他 Window 项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-04
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-28
    • 1970-01-01
    相关资源
    最近更新 更多