这里的控件是显示的元素

1、Item:一切的基类

  1. Item {
  2. Image {
  3. source: "tile.png"
  4. }
  5. Image {
  6. x:
  7. width:
  8. height:
  9. source: "tile.png"
  10. }
  11. Image {
  12. x:
  13. width:
  14. height:
  15. fillMode: Image.Tile
  16. source: "tile.png"
  17. }
  18. }

2、Rectangle:矩形

  1. Rectangle{
  2. width:300;
  3. height:200;
  4. color:"#C0C0C0";
  5. focus:true;
  6. Keys.enabled:true;
  7. Keys.onEscapePressed:Qt.quit();
  8. Keys.onBackPressed:Qt.quit();
  9. Keys.onPressed:{
  10. switch(event.key){
  11. case Qt.Key_0:
  12. case Qt.Key_1:
  13. case Qt.Key_2:
  14. case Qt.Key_3:
  15. case Qt.Key_4:
  16. case Qt.Key_5:
  17. case Qt.Key_6:
  18. case Qt.Key_7:
  19. case Qt.Key_8:
  20. case Qt.Key_9:
  21. event.accepted=true;
  22. keyView.text = event.key-Qt.Key_0;
  23. break;
  24. }
  25. }

3、Text:字

  1. Text{
  2. id:keyView;
  3. font.bold:true;
  4. font.pixelSize:;
  5. text:"Waiting";
  6. anchors.centerIn:parent;
  7. color:"#FF0000";
  8. }

4、Glow:光影

  1. Glow{
  2. anchors.fill:keyView;
  3. radius:;
  4. samples:;
  5. color:"white";
  6. source:keyView;
  7. }

5、PushButton:按钮

  1. Button{
  2. id:openBtn;//id
  3. text:"OPEN";//显示字
  4. anchors.left: parent.left;
  5. anchors.leftMargin: ;
  6. anchors.bottom: parent.bottom;
  7. anchors.bottomMargin: ;
  8. style:ButtonStyle{
  9. background: Rectangle{
  10. implicitWidth: ;
  11. implicitHeight: ;
  12. color:"#FFFFFF";
  13. border.width: control.pressed?:;
  14. border.color: (control.hovered || control.pressed)?"green":"#888888";
  15. }
  16. }
  17. onClicked:{
  18. //点击信号回调
  19. //fileDialog.open();
  20. }
  21. }

6、TabView,用TabViewStyle定制外观,注意手册中TabView没有style属性【实际上有,只是没有加上去】

  1. main.qml:
  2.  
  3. import QtQuick 2.6
  4. import QtQuick.Window 2.2
  5. import QtQuick.Controls 2.0
  6. import QtQuick.Controls 1.4
  7. Window {
  8. visible: true
  9. width:
  10. height:
  11. title: qsTr("Hello World")
  12.  
  13. TabView{
  14. anchors.fill: parent;
  15. style: TabViewStyle {
  16. frameOverlap:
  17. tabsAlignment: Qt.AlignHCenter
  18. tab: Rectangle {
  19. color: styleData.selected ? "steelblue" :"lightsteelblue"
  20. border.color: "steelblue"
  21. implicitWidth: Math.max(text.width + , )
  22. implicitHeight:
  23. radius:
  24. Text {
  25. id: text
  26. anchors.centerIn: parent
  27. text: styleData.title
  28. color: styleData.selected ? "white" : "black"
  29. }
  30. }
  31. frame: Rectangle { color: "steelblue" }
  32. }
  33. Tab {
  34. source:"tab.qml";
  35. }
  36. Tab {
  37. title: "Blue"
  38. Rectangle { color: "blue" }
  39. }
  40. Tab {
  41. title: "Green"
  42. Rectangle { color: "green" }
  43. }
  44. }
  45. }
  1. tab.qml:
  2.  
  3. import QtQuick 2.0
  4. import QtQuick.Controls 1.4
  5. Rectangle{
  6. Button{
  7. id:btn1;
  8. text: "";
  9. }
  10. Button{
  11. anchors.left: btn1.right;
  12. text: "";
  13. }
  14. }

7、行编辑:TextInput,TextField【比TextInput多了背景颜色设置】

8、块编辑:TextEdit,TextArea【比TextEdit多了背景颜色设置】

9、ExclusiveGroup,互斥分组,可以在里面放入RadioButton、CheckBox、Action等元素

  1. import QtQuick 2.6
  2. import QtQuick.Window 2.2
  3. import QtQuick.Controls 1.4
  4. Window {
  5. visible: true
  6. width:
  7. height:
  8. title: qsTr("Hello World")
  9.  
  10. Text {
  11. id: toptext;
  12. text: qsTr("请选择操作系统:");
  13. anchors.top: parent.top;
  14. anchors.topMargin: ;
  15. }
  16. Text{
  17. id:maintext;
  18. anchors.centerIn: parent;
  19. font.pixelSize: ;
  20. text:"no section";
  21. z:;
  22. }
  23.  
  24. ExclusiveGroup{
  25. id:eg;
  26. }
  27. RadioButton{
  28. id:btn1;
  29. text: "android";
  30. anchors.top:toptext.bottom;
  31. anchors.left: parent.left;
  32. anchors.leftMargin: ;
  33. exclusiveGroup: eg;
  34. anchors.topMargin: ;
  35. }
  36. RadioButton{
  37. id:btn2;
  38. text: "ios";
  39. anchors.top:btn1.bottom;
  40. anchors.left: parent.left;
  41. anchors.leftMargin: ;
  42. exclusiveGroup: eg;
  43. anchors.topMargin: ;
  44. }
  45. RadioButton{
  46. id:btn3;
  47. text: "windows";
  48. anchors.top:btn2.bottom;
  49. anchors.left: parent.left;
  50. anchors.leftMargin: ;
  51. exclusiveGroup: eg;
  52. anchors.topMargin: ;
  53. }
  54. RadioButton{
  55. id:btn4;
  56. text: "wh";
  57. anchors.top:btn3.bottom;
  58. anchors.left: parent.left;
  59. anchors.leftMargin: ;
  60. exclusiveGroup: eg;
  61. anchors.topMargin: ;
  62. }
  63. RadioButton{
  64. id:btn5;
  65. text: "linux";
  66. anchors.top:btn4.bottom;
  67. anchors.left: parent.left;
  68. anchors.leftMargin: ;
  69. exclusiveGroup: eg;
  70. anchors.topMargin: ;
  71. }
  72. Button{
  73. id:btn;
  74. text:"确定";
  75. anchors.top:btn5.bottom;
  76. anchors.left: parent.left;
  77. anchors.leftMargin: ;
  78. anchors.topMargin: ;
  79. onClicked: {
  80. maintext.text = eg.current.text;
  81. }
  82. }
  83. }

10、RadioButton,单旋按钮,使用RadioButtonStyle来设置风格

11、CheckBox,复选按钮,使用CheckBoxStyle来设置风格

  1. partiallyCheckedEnabled:用来表示可以部分选中
  1. CheckBox{
  2. id:btn5;
  3. text: "linux";
  4. partiallyCheckedEnabled: true;
  5. anchors.top:btn4.bottom;
  6. anchors.left: parent.left;
  7. anchors.leftMargin: ;
  8. anchors.topMargin: ;
  9. }

12、GroupBox

  1. import QtQuick 2.6
  2. import QtQuick.Window 2.2
  3. import QtQuick.Controls 1.4
  4. Window {
  5. visible: true
  6. width:
  7. height:
  8. title: qsTr("Hello World")
  9.  
  10. GroupBox{
  11. id:gb;
  12. title: "test";
  13. anchors.centerIn: parent;
  14. width: ;
  15. height: ;
  16. checkable: true;//是否可选
  17. flat: false;//是否有边框
  18. }
  19. }

13、ComboBox

  1. import QtQuick 2.6
  2. import QtQuick.Window 2.2
  3. import QtQuick.Controls 1.4
  4. Window {
  5. visible: true
  6. width:
  7. height:
  8. title: qsTr("Hello World")
  9.  
  10. ComboBox {
  11. anchors.centerIn: parent;
  12. currentIndex: ;
  13. //model: [ "Banana", "Apple", "Coconut" ]方式一
  14. model: ListModel {//方式二
  15. id: cbItems;
  16. ListElement { text: "Banana"; color: "Yellow" }
  17. ListElement { text: "Apple"; color: "Green" }
  18. ListElement { text: "Coconut"; color: "Brown" }
  19. }
  20. textRole: "color";//使用text或者color来显示
  21. width: ;
  22. onCurrentIndexChanged: {
  23. console.debug(cbItems.get(currentIndex).text + ", " + cbItems.get(currentIndex).color);//获取当前内容
  24. }
  25. }
  26. }

14、ProgressBar

  1. import QtQuick 2.6
  2. import QtQuick.Window 2.2
  3. import QtQuick.Controls 1.4
  4. Window {
  5. visible: true
  6. width:
  7. height:
  8. title: qsTr("Hello World")
  9. Column {
  10. anchors.centerIn: parent;
  11. ProgressBar {
  12. value: 0.5//当前值
  13. }
  14. ProgressBar {
  15. indeterminate: true//忙
  16. }
  17. }
  18. }

用ProgressBarStyle设置风格

15、Slider,使用SliderStyle来设置风格

Slider由四个部分组成,都可以定义

  1. import QtQuick 2.6
  2. import QtQuick.Window 2.2
  3. import QtQuick.Controls 1.4
  4. import QtQuick.Controls.Styles 1.4
  5. Window {
  6. visible: true
  7. width:
  8. height:
  9. title: qsTr("Hello World")
  10.  
  11. Text{
  12. id:text;
  13. anchors.top:parent.top;
  14. anchors.topMargin: ;
  15. anchors.left: parent.left;
  16. anchors.leftMargin: ;
  17. font.pixelSize: ;
  18. color:"red";
  19. text:"noooooo";
  20. }
  21.  
  22. Slider {
  23. anchors.centerIn: parent;
  24. width:;
  25. value: ;
  26. maximumValue: ;
  27. stepSize: ;
  28. tickmarksEnabled: true;
  29. onValueChanged: {//这个信号没有找到
  30. text.text=value;
  31. }
  32. style:SliderStyle{
  33. groove: Rectangle{
  34. width: ;
  35. height: ;
  36. radius: ;
  37. color: "green";
  38. }
  39. handle: Rectangle{
  40. width: ;
  41. height: ;
  42. radius: ;
  43. color: "red";
  44. }
  45. }
  46. }
  47. }

16、Flickable

17、Canvas

  1. import QtQuick 2.6
  2. import QtQuick.Window 2.2
  3. import QtQuick.Controls 1.4
  4. import QtQuick.Controls.Styles 1.4
  5. Window {
  6. visible: true
  7. width:
  8. height:
  9. title: qsTr("Hello World")
  10. Canvas {
  11. id: mycanvas
  12. width:
  13. height:
  14. onPaint: {
  15. var ctx = getContext("2d");
  16. ctx.fillStyle = Qt.rgba(, , , );
  17. ctx.fillRect(, , width, height);
  18. }
  19. }
  20. }

18、仪表盘CircularGauge

  1. import QtQuick 2.5
  2. import QtQuick.Controls 1.4
  3. import QtQuick.Controls.Styles 1.4
  4. import QtQuick.Extras 1.4
  5. CircularGauge {
  6. value: accelerating ? maximumValue :
  7. anchors.centerIn: parent
  8.  
  9. property bool accelerating: false
  10.  
  11. Keys.onSpacePressed: accelerating = true
  12. Keys.onReleased: {
  13. if (event.key === Qt.Key_Space) {
  14. accelerating = false;
  15. event.accepted = true;
  16. }
  17. }
  18.  
  19. Component.onCompleted: forceActiveFocus()
  20.  
  21. Behavior on value {
  22. NumberAnimation {
  23. duration:
  24. }
  25. }
  26. }

19、GridLayout

  1. GridLayout {
  2. id: grid
  3. rows:
  4. columns:
  5. width:
  6. height:
  7. columnSpacing:
  8. Text {
  9. id: textUsr
  10. text: qsTr("用户名")
  11. font.pointSize:
  12. color: "black"
  13. }
  14. TextField {
  15. id: filedUsr
  16. Layout.preferredHeight:
  17. }
  18. Text {
  19. id: textPaswd
  20. text: qsTr("密码")
  21. font.pointSize:
  22. color: "black"
  23. }
  24. TextField {
  25. id: filedPawd
  26. Layout.preferredHeight:
  27. }
  28. }

20、Image

  1. Image {
  2. id: rdJpg
  3. anchors.centerIn: parent
  4. smooth: true
  5. visible: false
  6. source: "qrc:/img/rd.jpg"
  7. }

如果是将图片全部存到了资源里,然后Image使用资源里的这些图片,最后打包的程序不需要再打包这些图片,因为已经跟随资源编译到程序里了,所以耗内存

QML常用控件的更多相关文章

  1. android内部培训视频_第三节(3)_常用控件(ViewPager、日期时间相关、ListView)

    第三节(2):常用控件之ViewPager.日期时间相关.ListView  一.ViewPager 实例:结合PagerAdapter滑动切换图片  二.日期时间相关:AnalogClock\Dig ...

  2. [WinForm]WinForm跨线程UI操作常用控件类大全

    前言 在C#开发的WinForm窗体程序开发的时候,经常会使用多线程处理一些比较耗时之类的操作.不过会有一个问题:就是涉及到跨线程操作UI元素. 相信才开始接触的人一定会遇上这个问题. 为了解决这个问 ...

  3. android内部培训视频_第三节 常用控件(Button,TextView,EditText,AutocompleteTextView)

    第三节:常用控件 一.Button 需要掌握的属性: 1.可切换的背景 2.9.png使用 3.按钮点击事件 1)  onClick 3) 匿名类 4) 公共类 二.TextView 常用属性 1.a ...

  4. Xamarin Studio在Mac环境下的配置和Xamarin.iOS常用控件的示例

    看过好多帖子都是Win环境装XS,Mac只是个模拟器,讲解在Mac环境下如何配置Xamarin Studio很少,也是一点点找资料,东拼西凑才把Xamarin Studio装在Mac上跑起来,如下: ...

  5. MFC编程入门之二十二(常用控件:按钮控件Button、Radio Button和Check Box)

    本节继续讲解常用控件--按钮控件的使用. 按钮控件简介 按钮控件包括命令按钮(Button).单选按钮(Radio Button)和复选框(Check Box)等.命令按钮就是我们前面多次提到的侠义的 ...

  6. MFC编程入门之二十(常用控件:静态文本框)

    上一节讲了颜色对话框之后,关于对话框的使用和各种通用对话框的介绍就到此为止了.从本节开始将讲解各种常用控件的用法.常用控件主要包括:静态文本框.编辑框.单选按钮.复选框.分组框.列表框.组合框.图片控 ...

  7. Android中常用控件及属性

    在之前的博客为大家带来了很多关于Android和jsp的介绍,本篇将为大家带来,关于Andriod中常用控件及属性的使用方法,目的方便大家遗忘时,及时复习参考.好了废话不多讲,现在开始我们本篇内容的介 ...

  8. DevExpress winform XtraEditor常用控件

    最近在公司里面开始使用DevExpress winform的第三方控件进行开发和维护,这里整理一些常用控件的资料以便于后续查看 ComboBoxEdit 这个控件和winform自带的控件差不多,使用 ...

  9. 五、Android学习第四天补充——Android的常用控件(转)

    (转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 五.Android学习第四天补充——Android的常用控件 熟悉常用的A ...

随机推荐

  1. Mysql date,datetime的区别以及相互转换

    参考:https://blog.csdn.net/a3025056/article/details/62885104/ 在数据库中一直有这三个时间类型有点搞不太清楚. 今天就来说一下之间的区别,其实是 ...

  2. MVC 中url-pattern配置为"/"和"/*"的区别

    首先大家都知道"/*"可以匹配所有url,包括带扩展名的,一般只用在过滤器上. 而"/"很多人理解成不能拦截带扩展名的,这种理解是错误的!它其实也能拦截“.js ...

  3. python中安装并使用redis

    数据缓存系统:1:mongodb:是直接持久化,直接存储于硬盘的缓存系统2:redis: 半持久化,存储于内存和硬盘3:memcache:数据只能存储在内存里的缓存系统 redis是一个key-val ...

  4. [13]Windows 内核情景分析 --- 网络通信

    典型的基于tcpip协议套接字方式的网络通信模块层次: 应用程序 socket api WS2_32.dll socket irp Afd.sys tdi irp Tcpip.sys 回调函数接口 各 ...

  5. 09 查找列表中元素,移除每个元素的空格,并查找以a或A开头并且以c结尾的所有元素

    li = ["alex"," aric","Alex","Tony","rain"]for i in ...

  6. 【转】python3实现自动化框架robotframework

    由于python2只更新到2020年,python3是未来的主流,为了适应技术的变化python3实现robotframework是迟早的事 1.下载最新版本的python3.7,可根据自己电脑的位数 ...

  7. cocos 搭建安卓环境

    http://blog.csdn.net/yiye3376/article/details/42219889

  8. Spark学习之路 (七)Spark 运行流程

    一.Spark中的基本概念 (1)Application:表示你的应用程序 (2)Driver:表示main()函数,创建SparkContext.由SparkContext负责与ClusterMan ...

  9. 浏览器页面请求js、css大文件处理

    当页面引用一个比较大的js和css文件时,会出现较大下载延迟,占用带宽的问题,如果一个应用里有很多这样的js或CSS文件,那么就需要优化了. 比如ext-all.js有1.4M,页面引用这个文件,正常 ...

  10. SLAM学习笔记 - 视觉SLAM方法资源汇总

    工具类: ros框架 linux系列教程     vim Eigen     Eigen快速入门 Pangolin  Pangolin安装与使用 数据集: TUM         数据格式 提供pyt ...