【learning log】Qt

  • Qt Quick

   Qt creator自带的入门 example。

  Qt designer 在 windows 下用起来还是很不方便,所以基本上直接用 code editor 反而更轻松。喜欢creator很重要一点就是因为它NB的代码补全。

   首先我们创建一个 qt quick 工程。把资源文件放到 main.qml 所在目录,然后 qt creator 就可以自动识别资源文件。

   先设置好image, 然后创建矩形,作为边框,这里背景设为透明,边框半径设为6,创造圆角效果。然后是一些对齐之类的设置。

   把 mouse area 放在 矩形下面(作为其子项, 在 designer 的 navigator 中 拖动 或者 在 code editor 中 添加都行),设置好layout, onClicked。

主要是实现点击图标,出现移动的效果。

   然后添加 State, 可以先 声明一个 states 集合, 然后在里面定义各个 State。

   State 里面最主要的就是 PropertChanges, 它改变一个 target 的 某个 property。这里是 icon 的坐标。

  然后定义 Transition。from:和 to:的对象可以写 ”*“, 代表任意对象。左键点击 NumberAnimation,等待一会会出现”小灯泡“。点它,出现对动画路径的选项面板,

  可以选择各种效果。

import QtQuick 2.0

Rectangle {
    id: page
    width: 360
    height: 360
    color: "#333333"

    Rectangle {
        id: topLeftRect
        x: 10
        y: 20
        width: 64
        height: 64
        color: "#00000000"
        radius: 6
        anchors.left: parent.left
        anchors.leftMargin: 10
        anchors.top: parent.top
        anchors.topMargin: 20
        border.width: 1
        border.color: "#808080"

        MouseArea {
            id: mouseArea
            anchors.fill: parent
            onClicked: {
                page.state = ‘ ‘
        }
    }
    }

    Image {
        id: icon
        x: 10
        y: 20
        source: "states.png"
    }

    Rectangle {
        id: middleRightRect
        width: 64
        height: 64
        color: "#00000000"
        radius: 6
        anchors.verticalCenter: parent.verticalCenter
        anchors.right: parent.right
        anchors.rightMargin: 10
        transformOrigin: Item.Center
        border.width: 1
        border.color: "#808080"
        MouseArea {
            id: mouseArea1
            anchors.fill: parent
            onClicked: page.state = ‘State1‘
        }
    }

    Rectangle {
        id: bottomLeftRect
        x: 6
        y: 28
        width: 64
        height: 64
        color: "#00000000"
        radius: 6
        anchors.left: parent.left
        anchors.leftMargin: 10
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 20
        border.width: 1
        MouseArea {
            id: mouseArea2
            anchors.fill: parent
            onClicked: page.state = ‘State2‘
        }
        border.color: "#808080"
    }
    states {
        State {
            name: "State1"
            PropertyChanges {
                target: icon
                x: middleRightRect.x
                y: middleRightRect.y
            }
        }
        State {
            name: "State2"
            PropertyChanges {
                target: icon
                x: bottomLeftRect.x
                y: bottomLeftRect.y
            }
        }
    }
    transitions {
        Transition {
            from: "*"
            to: "State1"
            NumberAnimation {
                easing.type: Easing.OutBounce
                properties: "x,y";
                duration: 1000
            }
        }
        Transition {
            from: "*"
            to: "State2"
            NumberAnimation {
                properties: "x, y"
                easing.type: Easing.InOutQuad
                duration: 2000
            }
        }
        Transition {
            NumberAnimation {
                properties: "x, y"
                duration: 2000
            }
        }
    }
}

main.qml

时间: 2024-08-05 15:18:30

【learning log】Qt的相关文章

【learning log】Linux network programming

DNS host entry 包含 DNS database 中有关某一 domin name 或 ip address 的 DNS 信息. 1 struct hostent{ 2 char *h_name; 3 char *h_aliases; 4 int h_addrtype; 5 int h_length; 6 char **h_addr_list; 7 }; hostinfo 程序, 用来从 ip 或 domin name 解析 DNS info. 1 /*This program is

【System Log】7月14日—7月29日

本日志由系统自动生成. 从7月14日起便按照心想事成的节奏进入了实验室.打酱油.周末又去学活值班,生活的框架还是很不错的. 1.基于Hadoop的Flume,zooKeeper,这些东西算是明白了个大概. 2.第一周大概学习了javascript.jquery.css.ci框架(php)这些基本的东西,然后大概搭了个大创网站的架子出来. 3.第二周周末开始写android,答应别人要开发的一个小游戏,但是写着写着就觉得压力大写不出来. 4.中间还抽时间看了程杰的大话设计模式,和一些人ctf的wr

【Learning Notes】线性链条件随机场(CRF)原理及实现

1. 概述条件随机场(Conditional Random Field, CRF)是概率图模型(Probabilistic Graphical Model)与区分性分类( Discriminative Classification)的一种接合,能够用来对“结构预测”(structured prediction,e.g. 序列标注)问题进行建模. 如图1,论文 [1] 阐释了 CRF 与其他模型之间的关系. 图1. CRF 与 其他机器学习模型对比[src] 本文我们重点关注输入结点独立的“线性链

【Learning Notes】变分自编码(Variational Auto-Encoder,VAE)

近年,随着有监督学习的低枝果实被采摘的所剩无几,无监督学习成为了研究热点.VAE(Variational Auto-Encoder,变分自编码器)[1,2] 和 GAN(Generative Adversarial Networks) 等模型,受到越来越多的关注. 笔者最近也在学习 VAE 的知识(从深度学习角度).首先,作为工程师,我想要正确的实现 VAE 算法,以及了解 VAE 能够帮助我们解决什么实际问题:作为人工智能从业者,我同时希望在一定程度上了解背后的原理. 作为学习笔记,本文按照由

【pyqtgraph绘图】Qt速成课程

解读官方API-Qt速成课程 参考:http://www.pyqtgraph.org/documentation/qtcrashcourse.html Qt速成课程 PyQtGraph广泛使用Qt来生成几乎所有的可视化输出和接口.Qt的文档编写得非常好,我们鼓励所有pyqtgraph开发人员熟悉它. 本节的目的是介绍使用Qt(使用PyQt或PySide)为pyqtgraph开发人员编程. QWidgets和布局 Qt GUI几乎总是由几个基本组件组成: 一个窗口.这通常由QMainWindow提

【coursera笔记】Machine Learning(Week6)

发现自己不写总结真是件很恶劣的事情,好多学的东西没有自己总结都忘记了.所以决定从今天开始,学东西的时候一定跟上总结. 我写的东西大多数是自己通俗的总结,不太喜欢写严格的定义或者证明,写了也记不住,欢迎指正. 1. High Bias vs. High Variance High Bias:通常是因为模型过于简单,使得不能成功拟合数据.比如说一些有二次曲线特性的数据,如果用一次直线去拟合就会出现这个问题,所以它对应了Underfitting问题.另外,从泛化角度来说,这样的模型泛化程度更高. Hi

【MySQL案例】error.log的Warning:If a crash happens thisconfiguration does not guarantee that the relay lo

1.1.1. If a crash happens thisconfiguration does not guarantee that the relay log info will be consistent [环境描述] msyql5.6.14 [报错信息] mysql的slave启动时,error.log中出现Warning警告: [Warning] Slave SQL: If a crash happensthis configuration does not guarantee tha

【大话QT之六】QT皮肤系统的动态切换

应用需求: 提供皮肤切换选项,在不重启应用程序的情况下实现皮肤的动态切换. 理论基础: 1) 图片资源是如何被利用的 这里先简要说明一下实现原理,皮肤的动态切换其关键在于图片资源的加载方式.QT中每个应用程序启动后都会维护属于自己的资源子库,所有的图片以及UI资源都实现编译到rcc文件中,而rcc文件是整合了所有资源的二进制文件,这种方式属于动态加载. 图片是一种资源,在QT中,对于资源的使用有以下几点: 1>  一般来说:资源在内存中是用资源对象树来表示的,该树在程序启动时创建. 2>   

【转】Qt使用自带的windeployqt 生成exe来发布软件

集成开发环境 QtCreator 目前生成图形界面程序 exe 大致可以分为两类:Qt Widgets Application  和 Qt Quick Application.下面分别介绍这两类exe 的发布方式. 第一类 Qt Widgets Application 可执行程序发布方式 意思是创建的 Qt Widgets Application 项目 下面来发布软件: 以 Release 方式编译生成 exe 程序,也就是调试运行的方式选择Release 生成完成后,在release文件夹下找