开发环境:

win8 + Qt5.11.2

说明:

用 QML 设计一个应用的登陆界面。

效果图:

新建一个 "Qt Quick Application - empty" 工程,分别添加 “main.qml” 、“LineInput.qml”、“ Button.qml” 这三个 qml 文件。

main.qml

import QtQuick 2.9

Rectangle {
id: loginWin
width: 320
height: 480
SystemPalette { id: activePalette } //背景图片
Image
{
id: background
anchors { top: parent.top; bottom: parent.bottom }
anchors.fill: parent
source: "./background.jpeg"
fillMode: Image.PreserveAspectCrop
} //顶栏
Item
{
id: topBar
width: loginWin.width; height: loginWin.height*0.05
anchors.top: loginWin.top
anchors.topMargin: 20 Text
{
id: title
anchors { top: parent.top; horizontalCenter: parent.horizontalCenter }
text: "登陆"
font.bold: true
font.pointSize: loginWin.height * 0.05 * 0.7
color: "dark red"
}
} //空白栏
Item
{
id: space
width: loginWin.width; height: loginWin.height * 0.1
anchors.top: topBar.bottom
} // 登录框
Rectangle {
id: loginRect
width: loginWin.width * 0.8
height: loginWin.height * 0.3
anchors { top: space.bottom; horizontalCenter: parent.horizontalCenter }
border.color: "#707070"
color: "transparent" LineInput
{
id: line
width: loginRect.width * 0.8; height: loginRect.height * 0.2
fontSize:height * 0.7
anchors { horizontalCenter: loginRect.horizontalCenter; top: loginRect.top; topMargin: 8 }
hint: "请输入用户号"
} LineInput
{
width: loginRect.width * 0.8; height: loginRect.height * 0.2
fontSize:height * 0.7
anchors { horizontalCenter: loginRect.horizontalCenter; bottom: loginButton.top; bottomMargin: loginRect.height * 0.1 }
hint: "请输入密码"
} Button
{
id: loginButton
width: loginRect.width * 0.35; height: loginRect.height * 0.2
anchors { left: loginRect.left; leftMargin: 28; bottom: loginRect.bottom; bottomMargin: 8 }
text: "登陆"
//onClicked: sameGame.startNewGame()
} Button
{
id: quitButton
width: loginRect.width * 0.35; height: loginRect.height * 0.2
anchors { right: loginRect.right; rightMargin: 28; bottom: loginRect.bottom; bottomMargin: 8 }
text: "退出"
//onClicked: sameGame.startNewGame()
}
}
}

LineInput.qml

import QtQuick 2.0

FocusScope {
id: wrapper // 定义可通过元对象系统访问的属性
property alias text: input.text
property alias hint: hint.text
property int fontSize: 18 // 自定义信号
signal accepted Rectangle {
anchors.fill: parent
border.color: "#707070"
color: "#c1c1c1"
radius: 4 // 输入栏隐藏文本
Text {
id: hint
anchors { fill: parent; leftMargin: 14 }
verticalAlignment: Text.AlignVCenter
text: "Enter word"
font.pixelSize: fontSize
color: "#707070"
opacity: input.length ? 0 : 1
} TextInput {
id: input
focus: true
anchors { left: parent.left; leftMargin: 14; right: parent.right; top: parent.top; bottom: parent.bottom }
verticalAlignment: Text.AlignVCenter
font.pixelSize: fontSize
color: "black"
maximumLength: 8 onAccepted: wrapper.accepted()
}
}
}

Button.qml

import QtQuick 2.0

Rectangle {
id: container property string text: "Button" signal clicked width: buttonLabel.width + 20; height: buttonLabel.height + 5
border { width: 1; color: Qt.darker(activePalette.button) }
antialiasing: true
radius: 8 // color the button with a gradient
gradient: Gradient {
GradientStop {
position: 0.0
color: {
if (mouseArea.pressed)
return activePalette.dark
else
return activePalette.light
}
}
GradientStop { position: 1.0; color: activePalette.button }
} MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: container.clicked();
} Text {
id: buttonLabel
anchors.centerIn: container
color: activePalette.buttonText
text: container.text
}
}

Qt Quick小项目 - 登陆界面的更多相关文章

  1. Qt 之 模仿 QQ登陆界面——样式篇

    一.简述 今天晚上花了半天时间从QQ登录界面抠了些图,顺便加了点样式基本上实现了QQ的登陆界面全部效果.虽不说100%相似,那也有99.99%相似了哈O(∩_∩)O. QQ好像从去年开始,登录界面有了 ...

  2. Android小项目之八 界面细节

    ------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 按惯例,写在前面的:可能在学习Android的过程中,大家会和我一样,学习过大量的基础知识,很多的知识点 ...

  3. [JAVA小项目]GUI界面的局域网聊天室

    思路: 1.服务端: 1.1 创建ServerSocket 监听本地端口 1.2 循环接收多个客户端的连接,并且把多个客户端连接的每个管道都为其创建线程. 服务端类的成员:链表--每个成员都是线程类- ...

  4. QT学习之路DAY1之初学QT的小项目

    以下所有代码均利用软件QT5编写 项目一:Hello world! 利用QTcreator创建项目 修改main.cpp代码为 #include "mainwindow.h" #i ...

  5. Qt编写小清新风格界面

    给一个朋友定制的界面,左侧有导航,左侧底部有运行+暂停+停止按钮,右侧有可伸缩面板,面板之间可以拉伸调节高度,左右两侧可以拉伸调节高度,所有的宽高和位置都保存在配置文件,下次重启立即应用,无边框标题栏 ...

  6. Qt Quick综合实例之文件查看器

    假设你基于Qt SDK 5.3.1来创建一个Qt Quick App项目,项目模板为你准备的main.qml文档的根元素是ApplicationWindow或Window.这次我们就以Applicat ...

  7. Qt Quick程序的发布

    要将程序发布出去,首先需要使用release方式编译程序,然后将生成的.exe可执行文件和需要的库文件发在一起打包进行发布. 要确定需要哪些动态库文件,可以直接双击.exe文件,提示缺少那个dll文件 ...

  8. QT5.3.1 Quick 开发 --- 项目类型的选择(转)

    原文转自 https://www.cnblogs.com/aoldman/p/3966025.html 作为一个转行QT开发的新手,面对基于QML的开发时候 看到很多的项目类型感到很困惑,不知道应该怎 ...

  9. qml(Qt Quick)做界面

    qml(Qt Quick)做界面 来源  https://www.zhihu.com/question/24880681/answer/29324824 本人是Qt初学者,正在写一个会计小软件(Lin ...

随机推荐

  1. Java 使用Navicat连接MySQL出现2059错误

    今天使用navicat链接mysql的时候报了2059的错误,找了很久才找到解决方法,这里记录一下.出现2059这个错误的原因是在mysql8之前的版本中加密规则为mysql_native_passw ...

  2. 使用Git Bash在码云上上传和下载代码

    前提是在码云上已经新建一个空的项目 1.新建一个目录,存放下载下来的项目,我在D盘新建了一个"gitspace"文件夹,用来存放下载下来的项目 2.进入刚刚新建的文件夹,即进入&q ...

  3. 阿里Jvm必问面试题及答案

    什么是Java虚拟机?为什么Java被称作是“平台无关的编程语言”? Java虚拟机是一个可以执行Java字节码的虚拟机进程.Java源文件被编译成能被Java虚拟机执行的字节码文件. Java被设计 ...

  4. jmeter-分布式压测部署之负载机的设置

    本文分三个部分: 1.windows下负载机的配置 2.Linux下负载机的配置 3.遇到的问题 *************************************************** ...

  5. C# 常用类库(字符串处理,汉字首字母拼音,注入攻击,缓存操作,Cookies操作,AES加密等)

    十年河东,十年河西,莫欺少年穷 学无止境,精益求精 记录下字符串类库,方便今后查阅 主要包含了字符串解决,去除HTML,SQL注入攻击检测,IP地址处理,Cookies操作,根据身份证获取性别.姓名. ...

  6. afnetwork使用

    Usage HTTP Request Operation Manager AFHTTPRequestOperationManager encapsulates the common patterns ...

  7. EFLAGS寄存器(标志寄存器)

    这篇文章不是从0开始的,前面还有一些汇编基础指令以及进制,我都没写,时间问题,还是今天空闲,我才想补一下博文,后面我陆续会把前面知识点渐渐补上.我不会重0基础讲起,中间会以.汇编.C.C++交叉的形式 ...

  8. ptrace函数深入分析

    ptrace函数:进程跟踪. 形式:#include<sys/ptrace.h> Int ptrace(int request,int pid,int addr,int data); 概述 ...

  9. python从入门到放弃之守护进程

    # ### 守护进程 默认情况下,主进程要等待所有子进程执行完毕之后,才会关闭程序,释放资源守护进程进行在主进程代码执行结束之后,就直接关闭;守护进程守护的是主进程 语法: 进程.daemon = T ...

  10. github 分支管理

    github 分支管理 最近有同事问我git 如何管理分支,这里我以github为例,做下工作中常用的分支管理操作. 分支管理 作用:假设你准备开发一个新功能,但需要两周才能完成,第一周写了60%,如 ...