开发环境:

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. C#中使用WCF创建面向网络的服务程序

    如题. 这种东西基于微软的一整套东西,在.NET内使用特别方便.利弊自行衡量,是否使用自行决定. 步骤1.创建一组在网上发布的方法 新建项目,类型选择“WCF服务应用程序”  在项目里,你可以补充任意 ...

  2. CentOS7 vsftp 安装与配置(视频教程)

    (双击全屏播放) 1.安装vsftpd yum install -y vsftpd 2.编辑ftp配置文件 vi /etc/vsftpd/vsftpd.conf anonymous_enable=NO ...

  3. Vue 拖拽组件 vuedraggable 和 vue-dragging

    一.描述 之前用 vue 写过一个在线的多二维码生成服务,体验地址:https://postbird.gitee.io/vue-online-qrcode/ 后面发现二维码多了之后有时候想要排序,需要 ...

  4. access truncate

    access int access(const char *pathname, int mode); 确定文件或文件夹的访问权限 //unistd.h #define R_OK 4 /* Test f ...

  5. 网页跳H5实例

    public static void CheckAgent() { string redirect = string.Empty; string agent = HttpContext.Current ...

  6. 还学不会webpack?看这篇!

    摘要: webpack入门教程. 原文:还学不会webpack?看这篇! 作者:MudOnTire Fundebug经授权转载,版权归原作者所有. Webpack已经流行好久了,但很多同学使用webp ...

  7. Apache:系统找不到指定的文件: No installed ConfigArgs for the service "Apache2"

    解决方法: 将以下内容保存成FixApacheError.reg文件(其中红色粗体Apache2改成报错的系统服务名称,如"RTX_HTTPServer"),导入系统注册表 Fix ...

  8. [基础]斯坦福cs231n课程视频笔记(一) 图片分类之使用线性分类器

    线性分类器的基本模型: f = Wx Loss Function and Optimization 1. LossFunction 衡量在当前的模型(参数矩阵W)的效果好坏 Multiclass SV ...

  9. PHP7.1-soap扩展安装

    1.下载php7.1.27源码包 cd /root & wget -O php7.1.27.tar.gz http://cn2.php.net/get/php-7.1.27.tar.gz/fr ...

  10. Spark之RDD

    Spark学习之路Spark之RDD 目录 一.RDD的概述 1.1 什么是RDD? RDD(Resilient Distributed Dataset)叫做弹性分布式数据集,是Spark中最基本的数 ...