Examples and fixes for QML Window properties
authorShawn Rutledge <shawn.rutledge@digia.com>
Mon, 22 Oct 2012 11:44:21 +0000 (13:44 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 9 Nov 2012 12:33:19 +0000 (13:33 +0100)
Setting Window.color in QML takes effect immediately.
It was only possible to set the property at startup.
Examples demonstrate new Window property features.

Change-Id: Ic5b43d0d84371f3fe5c42223ccc98e6de27aed10
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
examples/window/window/standalone.qml
examples/window/window/twowindows.qml
src/quick/items/qquickwindow.cpp
tools/qmlscene/main.cpp

index 079694c..a06db63 100644 (file)
@@ -44,13 +44,29 @@ import QtQuick.Window 2.0
 Item {
     width: 320
     height: 240
+    // It's not possible to set an Item's windowTitle.  If you want to modify
+    // window properties, you need to explicitly create a Window.
     Text {
+        id: text1
         anchors.centerIn: parent
         text: "First Window"
     }
     Rectangle {
         border.color: "black"
-        color: childWindow.visible ? "green" : "yellow"
+        radius: 4
+        anchors.top: text1.bottom
+        anchors.horizontalCenter: text1.horizontalCenter
+        width: 100
+        height: 30
+        TextInput {
+            id: ti1
+            focus: true // but the modal popup will prevent input while it is open
+            anchors.centerIn: parent
+        }
+    }
+    Rectangle {
+        border.color: "black"
+        color: childWindow.visible ? "goldenrod" : "beige"
         radius: height / 4
         anchors.bottom: parent.bottom
         anchors.right: parent.right
@@ -72,16 +88,39 @@ Item {
         id: childWindow
         width: 320
         height: 240
-        x: 320
-        y: 240
-        color: "green"
+        x: 220
+        y: 120
+        color: "beige"
+        title: "Second Window"
+        modality: Qt.ApplicationModal
+        flags: Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint
         Text {
+            id: text2
             anchors.centerIn: parent
-            text: "Second Window"
+            text: "Modal Frameless Stay-on-Top Window"
         }
-        MouseArea{
-            anchors.fill: parent
-            onClicked: Qt.quit()
+        Text {
+            anchors.top: parent.top
+            anchors.right: parent.right
+            anchors.margins: 10
+            text: "X"
+            MouseArea{
+                anchors.fill: parent
+                onClicked: childWindow.visible = false
+            }
+        }
+        Rectangle {
+            border.color: "black"
+            radius: 4
+            anchors.top: text2.bottom
+            anchors.horizontalCenter: text2.horizontalCenter
+            width: 100
+            height: 30
+            TextInput {
+                id: ti2
+                focus: true
+                anchors.centerIn: parent
+            }
         }
     }
 }
index b6e0f8a..345598c 100644 (file)
@@ -43,27 +43,47 @@ import QtQuick.Window 2.0
 
 QtObject {
     property var win1: Window {
-        width: 640
-        height: 480
+        width: 320
+        height: 240
         x: 0
         y: 0
         visible: true
         color: "#ccffff"
+        title: "First Window"
         Text {
             anchors.centerIn: parent
             text: "First Window"
+            Text {
+                id: statusText
+                anchors.top: parent.bottom
+                anchors.horizontalCenter: parent.horizontalCenter
+            }
+        }
+        MouseArea {
+            anchors.fill: parent
+            onClicked: win2.visible = !win2.visible
         }
     }
     property var win2: Window {
-        width: 640
-        height: 480
-        x: 640
-        y: 480
+        width: 320
+        height: 240
+        x: 220
+        y: 120
         visible: true
         color: "green"
-        Text {
-            anchors.centerIn: parent
-            text: "Second Window"
+        title: "Second Window: " + color
+        Rectangle {
+            anchors.fill: parent
+            anchors.margins: 10
+            Text {
+                anchors.centerIn: parent
+                text: "Second Window"
+            }
+            MouseArea {
+                anchors.fill: parent
+                onClicked: win2.color = "#ffffcc"
+            }
         }
+        onVisibleChanged: statusText.text = "second window is " + (visible ? "visible" : "invisible")
     }
 }
index 890474a..b341c6b 100644 (file)
@@ -2776,6 +2776,7 @@ void QQuickWindow::setColor(const QColor &color)
 
     d->clearColor = color;
     emit colorChanged(color);
+    d->dirtyItem(contentItem());
 }
 
 QColor QQuickWindow::color() const
index 55925a0..d41ade4 100644 (file)
@@ -476,6 +476,9 @@ int main(int argc, char ** argv)
                 if (contentItem) {
                     qxView = new QQuickView(&engine, NULL);
                     window = qxView;
+                    // Set window default properties; the qml can still override them
+                    QString oname = contentItem->objectName();
+                    window->setTitle(oname.isEmpty() ? QString::fromLatin1("qmlscene") : QString::fromLatin1("qmlscene: ") + oname);
                     window->setFlags(Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
                     if (options.resizeViewToRootItem)
                         qxView->setResizeMode(QQuickView::SizeViewToRootObject);