QML Button组件 及 定位器
来源:互联网 发布:淘宝男装代理货源网 编辑:程序博客网 时间:2024/05/29 16:27
新建Button.qml
import QtQuick 2.0Rectangle{ id:root //定义属性别名 text 值为label的text property alias text: label.text //定义信号名字 利用on实现调用函数 //signal clicked signal myClicked width: 116; height: 26 color: "lightsteelblue" border.color: "slategrey" radius:8 Text { id: label anchors.centerIn: parent text: "Start" } MouseArea { anchors.fill: parent onClicked: { //root.clicked() root.myClicek() } }}
主界面中调用:
import QtQuick 2.0import QtQuick.Window 2.2Window{ width: 300 height: 300 visible: true Button{ id:button x:12 y:12 //这里的text调用的是Button中定义的属性别名property alias text //如未定义 报错Cannot assign to non-existent property "text" text: "start" color: "blue" //onClicked: //利用on调用Button里定义的信号 onMyClicked:{ status.text = "gagagga...." button.color ="cyan" } } } Text { id: status x:12 y:76 width: 116 height: 26 text: qsTr("waiting...") anchors.centerIn: parent }}
定位器(Row{} Column{} Grid{} FLow{})
定义三个组件
BlueRectangle
import QtQuick 2.0Rectangle { width: 48 height: 48 color: "blue" //Qt.lighter(color) 颜色变亮 border.color: Qt.lighter(color)}
GreenRectangle
import QtQuick 2.0Rectangle { width: 48 height: 48 color: "green" border.color: Qt.lighter(color)}
RedRectangle
import QtQuick 2.0Rectangle { width: 48 height: 48 color: "red" border.width: 5 border.color: Qt.lighter(color)}
列定位:
Column{ id:col anchors.centerIn: parent spacing: 8 RedRectangle{ } BlueRectangle{ width: 94 } GreenRectangle{ } }
行定位:
Row{ id:row anchors.centerIn: parent spacing: 8 RedRectangle{ } BlueRectangle{ width: 94 } GreenRectangle{ } }
网格Grid定位:
Grid{ id:grid anchors.centerIn: parent //设置网格的行数 //rows:2 //设置网格的列数 //columns: 2 //不设置时网格默认列数为4 spacing: 8 RedRectangle { } RedRectangle { } RedRectangle { } RedRectangle { } RedRectangle { } }
Flow 结合LayoutDirection控制显示方式(流布局 宽度不够自动换行)
Flow { anchors.fill: parent //marigins 针对的是父元素的margin anchors.margins: 20 spacing: 20 RedRectangle { } BlueRectangle { } GreenRectangle { } }
Repeat 重复
0 0
- QML Button组件 及 定位器
- QML中Grid定位器
- QML中的Flow定位器
- QML之Column垂直定位器
- QML之Row水平定位器
- QML之Grid网格定位器
- QML概念及框架--QML文件和QML组件
- QML中定位器的相互嵌套
- QML中定位器和布局的区别
- QML布局管理—QML定位器和重复器
- 定位器
- QML之自定义Button
- QML类型说明-Button
- qml学习---------------Button属性
- qml学习------Button属性
- QML自定义控件Button
- QML之Button
- QML入门 Button 实现
- MOS管符号箭头指向问题
- curl 微信上传图片
- 线程面试题汇总30条
- Unity ugui的鼠标穿透问题
- oracle存储过程返回结果集SYS_REFCURSOR
- QML Button组件 及 定位器
- 8 Serializable序列化与反序列化
- jvm垃圾收集小记
- scikit-learn学习:elastic net
- React-Native知乎日报
- git常见命令总结
- 谈谈UIView的几个layout方法-layoutSubviews、layoutIfNeeded、setNeedsLayout...
- springmvc文件上传
- Java开发牛人十大必备网站