翻譯|使用教程|編輯:鮑佳佳|2020-08-06 10:44:41.410|閱讀 405 次
概述:本教程介紹如何開(kāi)發(fā)簡(jiǎn)單的鬧鐘應(yīng)用程序續(xù)篇:如何設(shè)置鬧鐘背景樣式等,附源代碼。此應(yīng)用程序類(lèi)似于通常在Android手機(jī)上找到的警鬧鐘應(yīng)用程序。它的功能使您可以輸入,編輯或刪除鬧鐘。鬧鐘可以在給定的日期觸發(fā),您可以將其設(shè)置為在隨后的幾天重復(fù)一次。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
Qt是目前最先進(jìn)、最完整的跨平臺(tái)C++開(kāi)發(fā)工具。它不僅完全實(shí)現(xiàn)了一次編寫(xiě),所有平臺(tái)無(wú)差別運(yùn)行,更提供了幾乎所有開(kāi)發(fā)過(guò)程中需要用到的工具。如今,Qt已被運(yùn)用于超過(guò)70個(gè)行業(yè)、數(shù)千家企業(yè),支持?jǐn)?shù)百萬(wàn)設(shè)備及應(yīng)用。
qtquickcontrols2.conf以下代碼片段顯示了如何設(shè)置Dark主題:
[Controls] Style=Material [Material] Theme=Dark Accent=Redmain.qml
mainWindow是ApplicationWindowQML類(lèi)型,是此應(yīng)用程序中的源項(xiàng)目。
ApplicationWindow { id: window width: 400 height: 500 visible: true
ListView alarmListView將alarmModel中的數(shù)據(jù)與alarmDelegate中定義的布局相結(jié)合。
ListView { id: alarmListView anchors.fill: parent model: AlarmModel {} delegate: AlarmDelegate {} }
單擊RoundButton 可以添加新鬧鐘addAlarmButton。單擊它會(huì)打開(kāi)一個(gè)對(duì)話框屏幕alarmDialog。
RoundButton { id: addAlarmButton text: "+" anchors.bottom: alarmListView.bottom anchors.bottomMargin: 8 anchors.horizontalCenter: parent.horizontalCenter onClicked: alarmDialog.open() } AlarmDialog { id: alarmDialog x: Math.round((parent.width - width) / 2) y: Math.round((parent.height - height) / 2) alarmModel: alarmListView.model }AlarmDialog.qml
這個(gè)對(duì)話框屏幕有一個(gè)行布局,每個(gè)行布局有一個(gè)轉(zhuǎn)筒,分別表示小時(shí)和分鐘;另一個(gè)行布局具有一個(gè)轉(zhuǎn)筒,分別表示天、月和年。
contentItem: RowLayout { RowLayout { id: rowTumbler Tumbler { id: hoursTumbler model: 24 delegate: TumblerDelegate { text: formatNumber(modelData) } } Tumbler { id: minutesTumbler model: 60 delegate: TumblerDelegate { text: formatNumber(modelData) } } } RowLayout { id: datePicker Layout.leftMargin: 20 property alias dayTumbler: dayTumbler property alias monthTumbler: monthTumbler property alias yearTumbler: yearTumbler readonly property var days: [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] Tumbler { id: dayTumbler function updateModel() { // Populate the model with days of the month. For example: [0, ..., 30] var previousIndex = dayTumbler.currentIndex var array = [] var newDays = datePicker.days[monthTumbler.currentIndex] for (var i = 1; i <= newDays; ++i) array.push(i) dayTumbler.model = array dayTumbler.currentIndex = Math.min(newDays - 1, previousIndex) } Component.onCompleted: updateModel() delegate: TumblerDelegate { text: formatNumber(modelData) } } Tumbler { id: monthTumbler onCurrentIndexChanged: dayTumbler.updateModel() model: 12 delegate: TumblerDelegate { text: window.locale.standaloneMonthName(modelData, Locale.ShortFormat) } } Tumbler { id: yearTumbler // This array is populated with the next three years. For example: [2018, 2019, 2020] readonly property var years: (function() { var currentYear = new Date().getFullYear() return [0, 1, 2].map(function(value) { return value + currentYear; }) })() model: years delegate: TumblerDelegate { text: formatNumber(modelData) } } } } }
如果在對(duì)話框中單擊“ 確定 ”,則輸入的數(shù)據(jù)將添加到alarmModel:
onAccepted: { alarmModel.append({ "hour": hoursTumbler.currentIndex, "minute": minutesTumbler.currentIndex, "day": dayTumbler.currentIndex + 1, "month": monthTumbler.currentIndex + 1, "year": yearTumbler.years[yearTumbler.currentIndex], "activated": true, "label": "", "repeat": false, "daysToRepeat": [ { "dayOfWeek": 0, "repeat": false }, { "dayOfWeek": 1, "repeat": false }, { "dayOfWeek": 2, "repeat": false }, { "dayOfWeek": 3, "repeat": false }, { "dayOfWeek": 4, "repeat": false }, { "dayOfWeek": 5, "repeat": false }, { "dayOfWeek": 6, "repeat": false } ], }) } onRejected: alarmDialog.close()
所有源文件代碼教程請(qǐng)關(guān)注后續(xù)文章。
點(diǎn)擊獲取更多相關(guān)類(lèi)產(chǎn)品文章信息
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: