Qt Quick小项目 - 登陆界面
开发环境:
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小项目 - 登陆界面的更多相关文章
- Qt 之 模仿 QQ登陆界面——样式篇
一.简述 今天晚上花了半天时间从QQ登录界面抠了些图,顺便加了点样式基本上实现了QQ的登陆界面全部效果.虽不说100%相似,那也有99.99%相似了哈O(∩_∩)O. QQ好像从去年开始,登录界面有了 ...
- Android小项目之八 界面细节
------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 按惯例,写在前面的:可能在学习Android的过程中,大家会和我一样,学习过大量的基础知识,很多的知识点 ...
- [JAVA小项目]GUI界面的局域网聊天室
思路: 1.服务端: 1.1 创建ServerSocket 监听本地端口 1.2 循环接收多个客户端的连接,并且把多个客户端连接的每个管道都为其创建线程. 服务端类的成员:链表--每个成员都是线程类- ...
- QT学习之路DAY1之初学QT的小项目
以下所有代码均利用软件QT5编写 项目一:Hello world! 利用QTcreator创建项目 修改main.cpp代码为 #include "mainwindow.h" #i ...
- Qt编写小清新风格界面
给一个朋友定制的界面,左侧有导航,左侧底部有运行+暂停+停止按钮,右侧有可伸缩面板,面板之间可以拉伸调节高度,左右两侧可以拉伸调节高度,所有的宽高和位置都保存在配置文件,下次重启立即应用,无边框标题栏 ...
- Qt Quick综合实例之文件查看器
假设你基于Qt SDK 5.3.1来创建一个Qt Quick App项目,项目模板为你准备的main.qml文档的根元素是ApplicationWindow或Window.这次我们就以Applicat ...
- Qt Quick程序的发布
要将程序发布出去,首先需要使用release方式编译程序,然后将生成的.exe可执行文件和需要的库文件发在一起打包进行发布. 要确定需要哪些动态库文件,可以直接双击.exe文件,提示缺少那个dll文件 ...
- QT5.3.1 Quick 开发 --- 项目类型的选择(转)
原文转自 https://www.cnblogs.com/aoldman/p/3966025.html 作为一个转行QT开发的新手,面对基于QML的开发时候 看到很多的项目类型感到很困惑,不知道应该怎 ...
- qml(Qt Quick)做界面
qml(Qt Quick)做界面 来源 https://www.zhihu.com/question/24880681/answer/29324824 本人是Qt初学者,正在写一个会计小软件(Lin ...
随机推荐
- CSS 控制文字两端对齐
<html> <head> <style> td:after { content: ''; } td p{ font-size: 14px; width: 5em; ...
- java架构之路-(nginx使用详解)nginx的反向代理和优化配置
书接上回说,nginx我们学会了简单的配置.那么我今天来聊一下,我们ngxin的一些优化配置(我不是很懂,不敢谈高级配置).我先来看一下nginx的好处和正向代理. nginx的好处 1.可以高并发连 ...
- .NET Core工作流引擎(RoadFlow)多语言版发布
经过两个月的辛苦努力.NET Core工作流引擎(RoadFlow)多语言版发布了,在原来只有一种简体中文语言的基础上增加了繁体中文和英文两种语言,还可以通过扩展增加任意语言包.至此RoadFlow工 ...
- netcore sdk版本选择
NetCore sdk并不是每个版本都支持VS2017工具,也不是每个版本的sdk版本号和Runtime版本号都一样,这就需要我们在创建某个版本的net core应用时注意: 使用不同版本的vs时需要 ...
- Python - 模块 - 第十六天
Python 模块 在前面的几个章节中我们脚本上是用 python 解释器来编程,如果你从 Python 解释器退出再进入,那么你定义的所有的方法和变量就都消失了. 为此 Python 提供了一个办法 ...
- shell 统计nginx日志中从指定日期到结束日期之间每天指定条件匹配的总次数
公司给出一个需求,指定时间内,统计请求driver.upload.position(司机位置上报接口)中,来源是华为push(come_from=huawei_push)的数量,要求是按天统计. 看一 ...
- 构建maven项目,自定义目录结构方法
构建maven项目 创建自定义的文件目录方法: 在项目名称右键-->Builder Path-->Configure Builder Path...Source菜单下的Add Folder ...
- django + pycharm 开局
1. 首先有 python3 2. 安装了pycharm 3. 配置开局 下面是用的全局的解释器,如果是用的虚拟环境的,Existing interpreter 选择虚拟环境的解释器. 4. set ...
- C++学习03_引用
基本使用 C++提供了给变量命名的机制,就是引用(Reference).引用是一种复合类型. //语法 数据类型 &name=data 注意,引用在定义时需要添加&,在使用时不能添加& ...
- JS高阶---原型面试
测试1: 分析如下 结果如下: 测试2: 测试3: 测试4: .