1、键盘加Text

import QtQuick 2.7
import QtGraphicalEffects 1.0
Rectangle{
width:;
height:;
color:"#C0C0C0";
focus:true;
Keys.enabled:true;
Keys.onEscapePressed:Qt.quit();
Keys.onBackPressed:Qt.quit();
Keys.onPressed:{
switch(event.key){
case Qt.Key_0:
case Qt.Key_1:
case Qt.Key_2:
case Qt.Key_3:
case Qt.Key_4:
case Qt.Key_5:
case Qt.Key_6:
case Qt.Key_7:
case Qt.Key_8:
case Qt.Key_9:
event.accepted=true;
keyView.text = event.key-Qt.Key_0;
break;
}
}
Text{
id:keyView;
font.bold:true;
font.pixelSize:;
text:"Waiting";
anchors.centerIn:parent;
color:"#FF0000";
}
Glow{//光影
anchors.fill:keyView;
radius:;
samples:;
color:"white";
source:keyView;
}
}

2、按钮+信号

import QtQuick 2.7
import QtQuick.Controls 2.2
Rectangle{
width:;
height:;
color:"gray";
Button{
text:"Quit";
anchors.centerIn:parent;
onClicked:Qt.quit();
}
}

3、TabBar

import QtQuick 2.7
import QtQuick.Controls 2.2
Rectangle{
width:;
height:;
color:"gray";
TabBar {
id:bar
width:parent.width
TabButton {
text:qsTr("Home")
}
TabButton {
text:qsTr("Discover")
}
TabButton {
text:qsTr("Activity")
}
 }
}

4、按钮+Compnent+风格

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.4
Rectangle{
width:;
height:;
Component{
id:btnStyle;
ButtonStyle{
background:Rectangle{
implicitWidth:;
implicitHeight:;
color:"#DDDDDD";
border.width:control.pressed?:;
border.color:(control.hovered||control.pressed)?"green":"#888888";
}
}
}
Button{ style:btnStyle;
}
}

5、矩形+颜色渐变+旋转

转自:https://blog.csdn.net/qq21497936/article/details/78526200
import QtQuick 2.2
import QtQuick.Controls 1.1
Item {
Rectangle {
x: ; width: ; height:
color: "lightsteelblue"
}
Rectangle {
x: ; width: ; height:
gradient: Gradient {
GradientStop { position: 0.0; color: "red" }
GradientStop { position: 0.5; color: "white" }
GradientStop { position: 1.0; color: "blue" }
}
}
Rectangle {
x: ; width: ; height:
rotation: // 旋转90度
gradient: Gradient { // 只能从上到下,若需要横向则需要旋转90°
GradientStop { position: 0.0; color: "red" }
GradientStop { position: 0.5; color: "white" }
GradientStop { position: 1.0; color: "blue" }
}
}
}

6、通过设置半径来画圆

转自:https://blog.csdn.net/qq21497936/article/details/78526200

import QtQuick 2.2

import QtQuick.Controls 1.1
Item {
Rectangle {
id: rect1;
width: ;
height: ;
radius: width/;
gradient: Gradient {
GradientStop { position: 0.0; color: "white"; }
GradientStop { position: 0.5; color: "blue"; }
GradientStop { position: 1.0; color: "white"; }
}
border.width: ;
border.color: "black";
}
}

7、简单的图片浏览器

import QtQuick 2.2
import QtQuick.Window 2.1
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Dialogs 1.1
Window {
visible: true;
width: ;
height: ;
title: "图片浏览器";
minimumWidth: ;
minimumHeight: ; BusyIndicator{
id: busy;
running: false;
anchors.centerIn: parent;
z:;
}
Text {
id: stateLabel;
visible: false;
anchors.centerIn: parent;
z:;
}
Image {
id: iamgeViewr;
asynchronous: true;
cache:false;
anchors.fill: parent;
fillMode: Image.PreserveAspectFit;
onStatusChanged: {
if(iamgeViewr.status===Image.Loading){
busy.running = true;
stateLabel.visible = false;
}
else if(iamgeViewr.status===Image.Ready){
busy.running=false;
}
else if(iamgeViewr.status===Image.Error)
{
busy.running = false;
stateLabel.visible = true;
stateLabel.text = "ERROR";
}
}
}
Text {
id: imagePath;
anchors.left: openFileBtn.right;
anchors.leftMargin: ;
anchors.verticalCenter: openFileBtn.verticalCenter;
font.pixelSize: ;
}
FileDialog{
id:fileDialog;
title: "open a picture";
nameFilters: ["Image Files(*.jpg *.png *.gif)"];
onAccepted: {
iamgeViewr.source = fileDialog.fileUrl;
var imageFile = String(fileDialog.fileUrl);
imagePath.text = imageFile.slice();
}
} Button{
id:openFileBtn;
text:"OPEN";
anchors.left: parent.left;
anchors.leftMargin: ;
anchors.bottom: parent.bottom;
anchors.bottomMargin: ;
style:ButtonStyle{
background: Rectangle{
implicitWidth: ;
implicitHeight: ;
color:"#FFFFFF";
border.width: control.pressed?:;
border.color: (control.hovered || control.pressed)?"green":"#888888";
}
}
onClicked: fileDialog.open();
z:;
}
}

8、颜色动画ColorAnimation

import QtQuick 2.2

Rectangle{
id: rootItem
width:
height:
color: "#EEEEEE" Rectangle{
id: rect
width:
height:
anchors.centerIn: parent
radius:
color: "red" MouseArea{
id: mouseArea
anchors.fill: parent
onClicked: ColorAnimation{
target: rect
property: "color"
to: "green"
duration:
}
}
}
}

9、MouseArea拖动

import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
Window {
visible: true
width:
height:
title: qsTr("Hello World")
Rectangle {
id: container
width: ; height: Rectangle {
id: rect
width: ; height:
color: "red"
opacity: (600.0 - rect.x) / MouseArea {
anchors.fill: rect
drag.target: rect
drag.axis:Drag.XAndYAxis
drag.minimumX:
drag.maximumX: container.width - rect.width
drag.minimumY:
drag.maximumY: container.width - rect.width
}
}
}
}

ps:试过给Window或者ApplicationWindow添加MouseArea来移动整个窗口,但是失败了。

分析:MouseArea只能移动有父类的Item

10、Keys

import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 1.4 Window {
id:main;
visible: true
width:
height:
Rectangle{
width: ;
height: ;
anchors.fill: parent;
focus:true;//获取焦点
Keys.enabled: true;//使能按键
Keys.forwardTo: text;//将按键事件传递到text对象
Rectangle {
id: text;
width: ;
height: ;
color: "red";
Keys.enabled: true;
Keys.onPressed: {
switch(event.key){
case Qt.Key_Left:
x-=;
break;
case Qt.Key_Right:
x+=;
break;
case Qt.Key_Down:
y+=;
break;
case Qt.Key_Up:
y-=;
break;
default:
break;
}
event.accepted = true;//在这里把按键事件吃了,不再向下传递
}
}
}
}

我的QML的更多相关文章

  1. QML 从无到有 3 (自动更新)

    新的需求出来啦,需要自动更新功能,不怕程序升级了. 自动更新,QML不好写,需要c++来辅助,这里就涉及QML中调用c++功能(这里就不写了,百度一下,很多). 思路:获取版本>下载程序> ...

  2. QML 从无到有 2 (移动适配)

    随着项目深入,需要移植到安卓上,问题来了,QML安卓适配! 幸好PC端程序和手机屏幕长宽比例相似.虽然单位像素,尺寸不同,通过比例缩放,可以实现组件PC和安卓通用代码. 第一步:定义全局的转换函数(3 ...

  3. QML 从无到有 (基础)

    小公司,没办法,什么都得自己亲自来. 服务端是MVC,现在需要可PC客户端和移动APP. 考虑到网页应用有很多界面框架,可以做出很漂亮的界面来,就尝试着使用nwjs来实现,可是在使用了2天的nwjs后 ...

  4. QML杂记

    1.QML编写可视化元素,运行后程序窗口上无显示.检查电脑的显卡是否支持OpenGL,如果支持请更新显卡驱动. 2.加载图片显示QML Image: Cannot open.解决在qml.qrc右击添 ...

  5. Qml 写的弹出层控件

    QML弹出窗口组件,灯箱效果.动画效果,可拖拽 核心思路:一个mask层,一个最顶层,都用rectangle,禁止事件穿透 使用 Popup { id: popup width: 200; heigh ...

  6. Qt qml 单例模式

    Qt qml 单例模式,没什么好说的,看代码吧.单例模式很适合做全局的配置文件. [示例下载] http://download.csdn.net/detail/surfsky/8539313 [以下是 ...

  7. Qt qml listview 列表视图控件(下拉刷新、上拉分页、滚动轴)

    Qt qml listview下拉刷新和上拉分页主要根据contentY来判断.但要加上顶部下拉指示器.滚动条,并封装成可简单调用的组件,着实花了我不少精力:) [先看效果]    [功能] 下拉刷新 ...

  8. Qt qml treeview 树控件

    qml并没有提供树控件,只能自己写了.model仍然用ListModel对象,弄成层级的就行.delegate必须用loader动态的增加子控件,如此而已. [先看效果] [下载] http://do ...

  9. qt qml qchart 图表组件

    qt qml qchart 图表组件 * Author: Julien Wintz * Created: Thu Feb 13 23:41:59 2014 (+0100) 这玩意是从chart.js迁 ...

  10. qt qml fuzzyPanel 毛玻璃效果

    毛玻璃效果,用qml来写代码真是简短,大爱qml:) [下载地址]http://download.csdn.net/detail/surfsky/8426641 [核心代码] Rectangle{ c ...

随机推荐

  1. mybatis之注解式开发之关联查询

    package com.bjsxt.mapper; import org.apache.ibatis.annotations.Select; import com.bjsxt.pojo.Clazz; ...

  2. 第六天实验详解——dedecms通过xss漏洞写马

    第六天实验详解 **XSS跨站攻击的分类** XSS漏洞类型主要分为持久型和非持久型两种: 1. 非持久型XSS漏洞一般存在于URL参数中,需要访问黑客构造好的特定URL才能触发漏洞. 2. 持久型X ...

  3. VS 应用模板 所交税和实发工资的运算

    double SFGZ, SL, SSKCS, YFGZ,a,YJS; //应发工资(基本工资),税率,速算扣除数,应发工资,判断标准,交多少税 //double QZD = 3500;//起征点 无 ...

  4. 018-AJAX异步请求XMLHttpRequest

    创建XMLHttpRequest对象 一.先来创建XMLHttpRequest对象在IE.Firefox.safari和Opera中创建该对象的JavaScript代码为: var xhr = new ...

  5. Javascript-双色球

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. PDO数据访问抽象层(下)

    PDO两大功能 一.事务功能 PDO的事务功能主要控制好几条sql语句同时成功或者同时失败(当其中一条SQL语句有错误时,同时好几条一起失败),失败时可以回滚操作 1.造对象 <?php $ds ...

  7. Vivado的安装程序没反应怎么办

    在Windows操作系统上,在安装Vivado的时候会遇到双击xsetup.exe没有反应的情况,即使是用管理员权限再加上设置兼容模式也没有任何效果,且此问题有可能在多个版本上都存在,包括最新的201 ...

  8. html中通过js获取接口JSON格式数据解析以及跨域问题

    前言:本人自学前端开发,一直想研究下js获取接口数据在html的实现,顺利地找到了获取数据的方法,但是有部分接口在调用中出现无法展示数据.经查,发现时跨域的问题,花费了一通时间,随笔记录下过程,以方便 ...

  9. django后台的制作

    参考:http://zengestudy.blog.51cto.com/1702365/1902660 http://www.cnblogs.com/fnng/p/3737964.html 实现与后台 ...

  10. CSS选择器的优先级及权重问题【CSS核心问题】及其它属性

    1.CSS选择器优先级:    !important >行间样式> id >class和属性选择器>标签选择器>通配符选择器        注意:[初级工程师水平] 2. ...