qml 一些知识点

1、pagestack进行页面调整的时候,需要对页面状态做一些跟踪:
Stack.onStatusChanged: {
if (Stack.status == Stack.Active) { //可以判断是否跳转完成
isPageReady = true
} else if (Stack.status == Stack.Inactive) {
isPageReady = false
}
}

2、qml中信号的使用

A.qml 中有一个函数实现

//选择案件后的回调事件
function setCaseInfo(name,legalid){
var info = {};
info.name = name;
info.legalid = legalid;

    caseText.text = name;
    downloadRec.caseId = legalid;
    var result = Storage.insert("caseinfo",JSON.stringify(info));
}

动态创建一个页面B并获取返回值:
MouseArea{
id : caseArea
anchors.fill: parent
onClicked: {
var content = Case.createElement("../caseStudy/AddCaseWin.qml",null);
content.caseselected.connect(setCaseInfo);
}
}

B页面有一个信号
signal caseselected(string name,int caseid)

B页面调用C组件:
ListView{
anchors.fill: parent
spacing: 25*screen.scale
clip: true
delegate: AddCaseItem{}
model:caseListModel
orientation:ListView.Horizontal
}

C组件则实现具体的参数透传:
MouseArea{
anchors.fill: parent
onClicked: {
caseselected(desction,legalid);
closeWin();
}
}

3.设置内部元素
default property alias contents: contents.data

    Item {
        id: contents

        width: flickable.width
        height: autoFlick ? childrenRect.height : flickable.height
    }

根据官方的意思:
data是默认属性,相当于子控件。childrenRect是用来访问子元素的宽高等信息

4.遍历指定类型的元素:
function getFlickableChild(item) {
if (item && item.hasOwnProperty("children")) {
for (var i=0; i < item.children.length; i++) {
var child = item.children[i];
if (internal.isVerticalFlickable(child)) {
if (child.anchors.top === page.top || child.anchors.fill === page) {
return item.children[i];
}
}
}
}
return null;
}

如何构建qml的模版:

They use default property alias ... to alias the child items to any property of any item. If you don't want to alias the children but give the alias property a name, just remove default. (Literal children are per QML definition the value of the default property.)

Item {
id: button
default property alias contents: placeholder.children

anchors.fill: parent

Rectangle {
    anchors.fill: parent
    radius: 10
    color: "gray"

    Item {
        id: placeholder     <-- where the placeholder should be inserted
    }
}

}

一个更具体的例子:
Dialog {
id: actionableDialog
title: "Change Text"
hasActions: true

    TextField {
        id: optionText
        text: currentText
        width: parent.width
        placeholderText: "New Option to Confirm"
    }

    onAccepted: {
        currentText = optionText.text
    }
}

Dialog.qml

PopupBase {
id: dialog

overlayLayer: "dialogOverlayLayer"
overlayColor: Qt.rgba(0, 0, 0, 0.3)

opacity: showing ? 1 : 0
visible: opacity > 0

width: Math.max(minimumWidth,
                content.contentWidth + 2 * contentMargins)

height: Math.min(units.dp(350),
                 headerView.height + units.dp(32) +
                 content.contentHeight +
                 content.topMargin +
                 content.bottomMargin +
                 buttonContainer.height)

property int contentMargins: units.dp(16)

property int minimumWidth: units.dp(270)

property alias title: titleLabel.text
property alias text: textLabel.text

/*!
   \qmlproperty Button negativeButton

   The negative button, displayed as the leftmost button on the right of the dialog buttons.
   This is usually used to dismiss the dialog.
 */
property alias negativeButton: negativeButton

/*!
   \qmlproperty Button primaryButton

   The primary button, displayed as the rightmost button in the dialog buttons row. This is
   usually used to accept the dialog's action.
 */
property alias positiveButton: positiveButton

property string negativeButtonText: "Cancel"
property string positiveButtonText: "Ok"
property alias positiveButtonEnabled: positiveButton.enabled

property bool hasActions: true

default property alias dialogContent: column.data

Flickable {
id: content

        contentWidth: column.implicitWidth
        contentHeight: column.height
        clip: true

        anchors {
            left: parent.left
            right: parent.right
            top: headerView.bottom
            topMargin: units.dp(8)
            bottomMargin: units.dp(-8)
            bottom: buttonContainer.top
        }

        interactive: contentHeight + units.dp(8) > height
        bottomMargin: hasActions ? 0 : units.dp(8)

        Rectangle {
            Column {
                id: column
                anchors {
                    left: parent.left
                    margins: contentMargins
                }

                width: content.width - 2 * contentMargins
                spacing: units.dp(16)
            }
        }
    }

}

转载于:https://www.cnblogs.com/xianqingzh/p/4349608.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: QML是一种用户界面定义语言,用于快速和轻松地创建跨平台的应用程序界面。与传统的图形对话框编程不同,QML通过使用声明性语法和元素组件来描述应用程序的图形界面。这使得界面的设计变得更加直观和易于理解。 OpenGL是一个用于开发图形应用程序的跨平台编程接口。它提供了一套功能强大的图形函数,可用于绘制2D和3D图形。OpenGL可以用于各种用途,如游戏开发、虚拟现实、数据可视化等。 在QML中使用OpenGL可以实现更高级的视觉效果和图形渲染。QML提供了一个OpenGL组件,可以轻松地将OpenGL内容嵌入到QML界面中。在QML中使用OpenGL,可以利用OpenGL的强大功能来实现复杂的图形效果和互动。 为了学习QML和OpenGL的结合使用,可以参考一些教程和文档。Qt官方网站提供了丰富的教程和示例,包括了使用QML和OpenGL的示例代码和文档。此外,还有一些第三方资源提供了有关QML和OpenGL的教程和示例代码。 学习QML和OpenGL的结合使用需要对QML和OpenGL的基础知识有一定的了解。首先,需要学习QML的语法和基本概念,如元素、属性和信号。然后,可以学习OpenGL的基本概念和函数,并了解如何在QML中使用OpenGL。 总之,QML和OpenGL的结合使用可以帮助我们创建更强大、更复杂的图形界面和视觉效果。通过学习相关教程和文档,我们可以掌握如何在QML中使用OpenGL,并利用其强大的功能来实现各种图形效果。 ### 回答2: QMl是一种用于创建用户界面的声明性语言,而OpenGL是一种用于实现3D图形渲染的开放图形库。结合起来,QML+OpenGL可以用于创建具有高效的3D图形渲染和动画效果的用户界面。 QML可以通过声明式的方式创建用户界面元素,并且具有良好的可视化能力和易于理解的语法。它支持丰富的UI控件和交互方式,同时还能轻松集成JavaScript代码来实现复杂的逻辑运算。在使用QML创建界面时,可以使用Qt Quick Controls提供的控件库或者自定义控件来满足特定需求。 而OpenGL是一种底层的图形库,用于实现高性能的3D图形渲染。通过OpenGL,可以直接进行硬件加速的图形操作,同时还可以利用图形硬件的强大计算能力,实现复杂的图形效果和计算。OpenGL提供了多种绘制图形的函数和接口,可以绘制点、线、多边形等不同类型的图形,并且可以进行纹理贴图、光照、阴影等高级渲染效果的实现。 QML+OpenGL的结合可以实现更为灵活且高效的用户界面设计。通过QML可以创建用户友好的界面元素,而OpenGL则可以在这些界面上实现更为复杂的3D图形渲染效果。在QML中,可以通过OpenGL的接口进行绘制和渲染操作,同时还可以将OpenGL渲染的结果嵌入到QML中,与其他界面元素进行交互。因此,通过学习QML+OpenGL教程,可以掌握如何使用QML和OpenGL结合起来创建出更为丰富和具有吸引力的用户界面。 ### 回答3: QML和OpenGL是两个不同的技术,但可以结合使用来创建各种交互式和图形密集型应用程序。下面是关于QML和OpenGL的简要介绍: QML是一种声明式的用户界面语言,用于创建功能丰富、跨平台的应用程序。它使用一种类似于JSON的语法来描述用户界面,可以通过编写更少的代码实现复杂的交互效果。QML具有良好的可扩展性和可重用性,并且易于理解和学习。它是Qt框架的一部分,因此可以与C++和其他Qt模块(如QtQuick)进行混合编程。 OpenGL是一种跨平台的图形库,用于渲染3D图形和执行其他图形操作。它提供了一套功能强大的API,可以绘制复杂的图形和执行高性能的计算。OpenGL可用于在各种设备上实现流畅的图形渲染,包括计算机、移动设备和嵌入式系统等。它支持多种图形效果,如阴影、反射、纹理映射和动画等。 QML和OpenGL可以结合使用来创建更具吸引力和交互性的用户界面。通过将QML和OpenGL结合起来,可以在QML界面中嵌入OpenGL渲染区域,并通过QML的声明式语法控制OpenGL渲染的效果和交互行为。这种混合编程的方法将QML的易用性和OpenGL的功能强大结合在一起,可以实现更高级的图形效果和用户交互。 总结而言,QML和OpenGL都是强大的技术,分别用于创建用户界面和图形渲染。结合使用它们可以实现各种复杂的应用程序,并为用户提供更好的视觉体验和交互性。如果您对QML和OpenGL有兴趣,可以参考官方文档和教程,以了解更多详细信息和开始使用它们。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值