2014-09-27 156 views
-1

我正在使用Qt Creator的Qt Quick,并且按照教程中的建议,我为每个按钮制作了不同的.qml。Qt创建者:按钮点击Signal弹出一个窗口

我希望当点击按钮使窗口弹出。我应该写什么

onClicked: 

在mouseArea中。

另外如何制作第二个窗口(弹出式窗口),我应该如何添加到项目中,以便像主窗口那样设计它?

我读到我必须创建一个继承QWidget的类,但我需要更多信息。

一个简短的例子会很棒。

回答

0

在本教程建议我为每一个按钮

当然,你的意思是“为每个按钮类型”由不同.qml!?

启动第二个窗口:

// Main.qml 
Window { 
    id: win 
    width: 640 
    height: 480 

    Button { 
     text: qsTr("Open") 
     anchors.horizontalCenter: parent.horizontalCenter 
     anchors.verticalCenter: parent.verticalCenter 

     onClicked: { 
      var factory = Qt.createComponent("Popup.qml"); 
      factory.createObject(win); 
     } 
    } 
} 

// Popup.qml 
Window { 
    height: 240 
    width: 320 
    title: qsTr("Popup") 
    visible: true 

    Text { 
     text: qsTr("Hello") 
     anchors.centerIn: parent 
    } 
} 

我阅读,我不得不做出这样的与QWidget的继承的类

不要混合QML和Qt窗口小部件模块,除非你是扩展/转换遗留系统,QML已被设计为替换Qt Widgets(在某些时候)。