当前位置: 首页 > news >正文

苏州做网站建设公司南通网站设计制作公司

苏州做网站建设公司,南通网站设计制作公司,网站怎么做飘窗,谷歌推广哪家公司好二级界面显示效果 方式一 :局部变量方式局部变量方式实现步骤:1.在调用方qml文件中注册组件;2.在调用方qml文件中初始化该组件的对象;3.在调用方qml文件中指定控件下使用该对象,实现二级界面显示.调用方qml文件关键实现import QtQuick 2.1 import QtQuick.Controls …

二级界面显示效果 

方式一 :局部变量方式

            局部变量方式实现步骤:

                1.在调用方qml文件中注册组件;

                2.在调用方qml文件中初始化该组件的对象;

                3.在调用方qml文件中指定控件下使用该对象,实现二级界面显示.

        调用方qml文件关键实现

import QtQuick 2.1
import QtQuick.Controls 2.1ItemDelegate {id: delegateRow...//注册组件Component {id: musicPropertyDialogSetMetaInfo {id: setMetaInfosenderObj: musicProperty}}//初始化组件property var dialog: nullComponent.onCompleted: {dialog  = musicPropertyDialog.createObject()}...MouseArea {anchors.fill: parenthoverEnabled: trueacceptedButtons: Qt.LeftButton | Qt.RightButtoncursorShape: styleData.row === undefined ? Qt.ArrowCursor : Qt.PointingHandCursoronDoubleClicked: dataModel.play()onClicked: {if (mouse.button === Qt.LeftButton && styleData.row !== undefined) {
//                console.log("Индекс делегата " + styleData.row)
//                songLabelContainer.songLabel.text = model.artist
//                dataModel.setCurrentMedia(model.index)if (isCurrentMediaPlaying) {dataModel.pause()}tableView.currentRow = styleData.rowdataModel.setCurrentMedia(styleData.row)tableView.selection.clear()tableView.selection.select(styleData.row)}else if (mouse.button === Qt.RightButton && styleData.row !== undefined) {console.log("CLICKED")hideMenu.popup()}}Menu {id: hideMenuwidth: 100height: 150MenuItem {id: menuItemtext: "删除"implicitHeight: 30implicitWidth: 100onTriggered: dataModel.removeRow(styleData.row)background: Rectangle {width: menuItem.widthheight: menuItem.heightradius: 5color: menuItem.hovered ? "lightblue" : "white"}contentItem: Text {text: menuItem.textcolor: menuItem.hovered ? "white" : "black"horizontalAlignment: Text.AlignHCenterverticalAlignment: Text.AlignVCenter}}MenuItem{id: goToLiricstext: "转到歌词"implicitHeight: 30implicitWidth: 100onTriggered: {}background: Rectangle {width: goToLirics.widthheight: goToLirics.heightradius: 5color: goToLirics.hovered ? "lightblue" : "white"}contentItem: Text {text: goToLirics.textcolor: goToLirics.hovered ? "white" : "black"horizontalAlignment: Text.AlignHCenterverticalAlignment: Text.AlignVCenter}}MenuItem{id: musicPropertytext: "属性"implicitHeight: 30implicitWidth: 100//定义一个信号signal updateMusicProperty(string msg)onTriggered: {//局部变量实现属性对话框的显示if(dialog){dialog.show();}updateMusicProperty("更新音乐属性##")//发送信号给属性界面}background: Rectangle {width: musicProperty.widthheight: musicProperty.heightradius: 5color: musicProperty.hovered ? "lightblue" : "white"}contentItem: Text {text: musicProperty.textcolor: musicProperty.hovered ? "white" : "black"horizontalAlignment: Text.AlignHCenterverticalAlignment: Text.AlignVCenter}}}}
}

        二级界面qml文件关键实现


import QtQuick 2.1
import QtQuick.Window 2.1
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3Window {id: roottitle: "音乐属性编辑"flags: Qt.Dialog // 设置为对话框样式modality: Qt.ApplicationModalwidth: 335height: 248property string songTitle: ""property string artist: ""property string duration: "03:45"property string album: ""//绑定发送对象property var senderObj: nullComponent.onCompleted: {if(senderObj) {//绑定发送对象信号与当前函数senderObj.updateMusicProperty.connect(handleMessage)}}function handleMessage(msg) {
//        console.log("SetMeaInfo UI Received:", msg)var data = dataModel.metaDatasongTitle = String(data["title"])artist = String(data["artist"])duration = String(data["time"])album = String(data["album"])console.log("songTitle:",songTitle," artist:",artist," duration:",duration," album:",album)}Column{anchors.centerIn: parentspacing: 10ColumnLayout {spacing: 15GridLayout {columns: 2columnSpacing: 20rowSpacing: 10Label { text: "标题:" }TextField {id: titleFieldtext: root.songTitleLayout.fillWidth: trueonTextChanged: root.songTitle = text}Label { text: "艺术家:" }TextField {id: artistFieldtext: root.artistLayout.fillWidth: trueonTextChanged: root.artist = text}Label { text: "时长:" }TextField {id: durationFieldtext: root.durationreadOnly: trueLayout.fillWidth: truecolor: "gray"}Label { text: "专辑:" }TextField {id: albumFieldtext: root.albumLayout.fillWidth: trueonTextChanged: root.album = text}}}Row{anchors.right: parent.rightspacing: 10Button{width: 80height:  30text: '确定'onClicked: {if(titleField.text === ""||artistField.text === ""||durationField.text === ""||albumField.text === ""){console.log("music property can't is null")return}var metaData = {"title": titleField.text,"artist":artistField.text,"album": albumField.text}dataModel.metaData = metaData;root.hide()}}Button{width: 80height:  30text: '取消'onClicked: root.hide()}}}}

方式二:全局变量方式

          全局变量方式实现步骤 :

        1.在全局main.qml中将二级界面注册为全局属性;

        2.在其它qml文件中使用该属性创建对象 ;

        3.在调用的地方使用该对象.

全局qml文件中关键实现

import QtQuick 2.1
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.3
import QtQuick.Window 2.1ApplicationWindow {id: rootwidth: 860height: 600visible: trueminimumHeight: 600minimumWidth: 800title: qsTr("音乐播放器")...//注册全局属性Item {Component.onCompleted: {// 将组件注册为全局属性Qt._musicPropertyDlg = Qt.createComponent("SetMetaInfo.qml")}}...}

调用方qml文件关键实现

import QtQuick 2.1
import QtQuick.Controls 2.1
import MusicProperty 1.0ItemDelegate {id: delegateRow...MouseArea {anchors.fill: parenthoverEnabled: trueacceptedButtons: Qt.LeftButton | Qt.RightButtoncursorShape: styleData.row === undefined ? Qt.ArrowCursor : Qt.PointingHandCursoronDoubleClicked: dataModel.play()Menu {id: hideMenuwidth: 100height: 50MenuItem{id: musicPropertytext: "属性"implicitHeight: 30implicitWidth: 100onTriggered: {... //2.全局变量实现属性对话框的显示let dialog = Qt._musicPropertyDlg.createObject(delegateRow)dialog.show()dialog.handleMessage('msg')...}background: Rectangle {width: musicProperty.widthheight: musicProperty.heightradius: 5color: musicProperty.hovered ? "lightblue" : "white"}contentItem: Text {text: musicProperty.textcolor: musicProperty.hovered ? "white" : "black"horizontalAlignment: Text.AlignHCenterverticalAlignment: Text.AlignVCenter}}}}
}

二级界面qml文件关键实现


import QtQuick 2.1
import QtQuick.Window 2.1
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3Window {id: roottitle: "音乐属性编辑"flags: Qt.Dialog // 设置为对话框样式modality: Qt.ApplicationModalwidth: 335height: 248property string songTitle: ""property string artist: ""property string duration: "03:45"property string album: ""...function handleMessage(msg) {
//        console.log("SetMeaInfo UI Received:", msg)var data = dataModel.metaDatasongTitle = String(data["title"])artist = String(data["artist"])duration = String(data["time"])album = String(data["album"])console.log("songTitle:",songTitle," artist:",artist," duration:",duration," album:",album)}...Column{anchors.centerIn: parentspacing: 10ColumnLayout {spacing: 15GridLayout {columns: 2columnSpacing: 20rowSpacing: 10Label { text: "标题:" }TextField {id: titleFieldtext: root.songTitleLayout.fillWidth: trueonTextChanged: root.songTitle = text}Label { text: "艺术家:" }TextField {id: artistFieldtext: root.artistLayout.fillWidth: trueonTextChanged: root.artist = text}Label { text: "时长:" }TextField {id: durationFieldtext: root.durationreadOnly: trueLayout.fillWidth: truecolor: "gray"}Label { text: "专辑:" }TextField {id: albumFieldtext: root.albumLayout.fillWidth: trueonTextChanged: root.album = text}}}Row{anchors.right: parent.rightspacing: 10Button{width: 80height:  30text: '确定'onClicked: {if(titleField.text === ""||artistField.text === ""||durationField.text === ""||albumField.text === ""){console.log("music property can't is null")return}var metaData = {"title": titleField.text,"artist":artistField.text,"album": albumField.text}dataModel.metaData = metaData;root.hide()}}Button{width: 80height:  30text: '取消'onClicked: root.hide()}}}}

方式三:模块化方式

        模块化方式实现步骤:

        1.定义一个模块化目录qmlModel;

        2.将该二级界面实现一个模块化文件;

        3.将该模块化文件添加到qml引擎中;

        4.在调用方qml文件中通过 import方式导入 该二级界面 ;

        5.在调用方qml文件中指定位置使用该模块 .

模块化文件

qmldir文件实现

module MusicProperty
MusicProperty 1.0 MusicProperty.qml

调用方qml文件关键实现

import QtQuick 2.1
import QtQuick.Controls 2.1
//引入二级界面模块
import MusicProperty 1.0ItemDelegate {id: delegateRowproperty int heightRows: 50property bool isCurrentMediaPlaying: dataModel.mediaPlayerState === 1&& dataModel.currentMediaIndex === styleData.row//声明二级界面 MusicProperty{id: mProperty}MouseArea {anchors.fill: parenthoverEnabled: trueacceptedButtons: Qt.LeftButton | Qt.RightButtoncursorShape: styleData.row === undefined ? Qt.ArrowCursor : Qt.PointingHandCursoronDoubleClicked: dataModel.play()Menu {id: hideMenuwidth: 100height: 50MenuItem{id: musicPropertytext: "属性"implicitHeight: 30implicitWidth: 100...onTriggered: {//3.模块化调用实现二级界面属性对话框的显示mProperty.open()}...background: Rectangle {width: musicProperty.widthheight: musicProperty.heightradius: 5color: musicProperty.hovered ? "lightblue" : "white"}contentItem: Text {text: musicProperty.textcolor: musicProperty.hovered ? "white" : "black"horizontalAlignment: Text.AlignHCenterverticalAlignment: Text.AlignVCenter}}}}
}

二级界面qml文件关键实现

import QtQuick 2.1
import QtQuick.Window 2.1
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3Item{...function open() {root.show()root.handleMessage("")}...Window {id: roottitle: "音乐属性编辑"flags: Qt.Dialog // 设置为对话框样式modality: Qt.ApplicationModalwidth: 335height: 248property string songTitle: ""property string artist: ""property string duration: "03:45"property string album: ""function handleMessage(msg) {
//        console.log("SetMeaInfo UI Received:", msg)var data = dataModel.metaDatasongTitle = String(data["title"])artist = String(data["artist"])duration = String(data["time"])album = String(data["album"])console.log("songTitle:",songTitle," artist:",artist," duration:",duration," album:",album)}Column{anchors.centerIn: parentspacing: 10ColumnLayout {spacing: 15GridLayout {columns: 2columnSpacing: 20rowSpacing: 10Label { text: "标题:" }TextField {id: titleFieldtext: root.songTitleLayout.fillWidth: trueonTextChanged: root.songTitle = text}Label { text: "艺术家:" }TextField {id: artistFieldtext: root.artistLayout.fillWidth: trueonTextChanged: root.artist = text}Label { text: "时长:" }TextField {id: durationFieldtext: root.durationreadOnly: trueLayout.fillWidth: truecolor: "gray"}Label { text: "专辑:" }TextField {id: albumFieldtext: root.albumLayout.fillWidth: trueonTextChanged: root.album = text}}}Row{anchors.right: parent.rightspacing: 10Button{width: 80height:  30text: '确定'onClicked: {if(titleField.text === ""||artistField.text === ""||durationField.text === ""||albumField.text === ""){console.log("music property can't is null")return}var metaData = {"title": titleField.text,"artist":artistField.text,"album": albumField.text}dataModel.metaData = metaData;root.hide()}}Button{width: 80height:  30text: '取消'onClicked: root.hide()}}}}}

引入模块路径

QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.addImportPath("/home/ubuntu/packet/gitpro/MediaPlayer/qmlModel");
engine.load(url);

模块化文件结构

Project/
├── qmlModel/
│   └── MusicProperty/
│       │   ├── qmldir
│       │   └── MusicProperty.qml

http://www.dtcms.com/a/563071.html

相关文章:

  • wordpress的php.ini沈阳seo建站
  • 网站cms系统企业年金的好处和坏处
  • 茶叶网站模板免费下载青海省城乡和住房建设厅网站
  • 广州营销型网站建设费用免费看片网站
  • 县建设局 协会网站私人订制网站推荐
  • 计算机网络技术是干嘛的网站在线优化
  • 一个人网站运营怎么做网站后台统计代码
  • jsp网站开发 孟浩pdf简单又快的科学小制作
  • 国际网站怎么建设微商城开发用华网天下北京
  • 常用博客建站程序搜索引擎优化关键词选择的方法有哪些
  • 网站未在腾讯云备案沈阳市建设工程质量监督局网站
  • 优秀网站建设济南网站制作哪家专业
  • 东莞做网站it s实体电商app定制开发
  • 网站建设开发服务费怎么做分录如何制作一个网站包含多个网页
  • 嘉兴网站建设科技有限公司广东工程建设监理有限公司网站
  • Python每日一练---第一天:买卖股票的最佳时机
  • 网站可以做什么企业网站建设专家
  • 上海响应式网站开发深圳的网站建设公司哪家好
  • wordpress编辑富文seo推广有效果吗
  • 淮北论坛最新招聘信息网如何提升seo
  • 用dw做网站背景关于二手书的网站开发ppt
  • 企业品牌网站建设首选公司网站搭建修改收费依据
  • 河南企业建设网站网站建设的课件
  • 具有品牌的网站建设上海网站排名团队
  • 杭州科技网站作文库网站
  • 建站设计网站微信公众号的子菜单网页怎么制作
  • wordpress插件ssh东莞seo网络营销策划
  • 网站自然排名这么做微信小商店分销功能
  • 做钓鱼网站判刑中国建设人才服务信息网站
  • 网页设计公司平台凤山网站seo