原創(chuàng)|使用教程|編輯:龔雪|2016-03-14 09:26:45.000|閱讀 1637 次
概述:本教程介紹如何使用ui.qml文件開發(fā)一個應(yīng)用程序,使應(yīng)用程序邏輯從UI中分離。該教程使用Qt Quick Designer實(shí)現(xiàn)一個簡化版的UI表單示例,它為一個客戶數(shù)據(jù)庫提供接口,只用QML和JavaScript編寫。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
向?qū)砑右粋€菜單欄到main.qml文件中,這其中包含了一個具有Open和Exit菜單的File菜單。保存菜單和Exit菜單項(xiàng),然后添加具有標(biāo)準(zhǔn)菜單項(xiàng)的Edit和Help菜單。
該向?qū)?chuàng)建下面的代碼:
menuBar: MenuBar { Menu { title: qsTr("&File") MenuItem { text: qsTr("&Open") onTriggered: messageDialog.show(qsTr("Open action triggered")); } MenuItem { text: qsTr("E&xit") onTriggered: Qt.quit(); } } }
刪除Open菜單項(xiàng)并添加下面的代碼來創(chuàng)建新的菜單:
menuBar: MenuBar { Menu { title: qsTr("&File") MenuItem { text: qsTr("E&xit") onTriggered: Qt.quit(); } } Menu { title: qsTr("&Edit") MenuItem { action: cutAction } MenuItem { action: copyAction } MenuItem { action: pasteAction } } Menu { title: qsTr("&Help") MenuItem { text: qsTr("About...") onTriggered: aboutDialog.open() } } } Action { id: copyAction text: qsTr("&Copy") shortcut: StandardKey.Copy iconName: "edit-copy" enabled: (!!activeFocusItem && !!activeFocusItem["copy"]) onTriggered: activeFocusItem.copy() } Action { id: cutAction text: qsTr("Cu&t") shortcut: StandardKey.Cut iconName: "edit-cut" enabled: (!!activeFocusItem && !!activeFocusItem["cut"]) onTriggered: activeFocusItem.cut() } Action { id: pasteAction text: qsTr("&Paste") shortcut: StandardKey.Paste iconName: "edit-paste" enabled: (!!activeFocusItem && !!activeFocusItem["paste"]) onTriggered: activeFocusItem.paste() }
該向?qū)⒃趍ain.qml文件文件中創(chuàng)建一個消息對話框:
MessageDialog { id: messageDialog title: qsTr("May I have your attention, please?") function show(caption) { messageDialog.text = caption; messageDialog.open(); }
通過向?qū)薷谋粍?chuàng)建的代碼來添加一個圖標(biāo)或一些文本:
MessageDialog { id: aboutDialog icon: StandardIcon.Information title: qsTr("About") text: "Qt Quick UI Forms" informativeText: qsTr("This example demonstrates how to separate the " + "implementation of an application from the UI " + "using ui.qml files.") }
從您創(chuàng)建的Help菜單中啟動訪問About對話框。
該應(yīng)用程序已經(jīng)完成,隨時可以在桌面上運(yùn)行或部署到設(shè)備上。要運(yùn)行應(yīng)用程序,按Ctrl+ R。
文件:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)