QML设计登陆界面

本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明.



环境:

主机:WIN7

开发环境:Qt5.2

说明:

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

效果图:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamRoOTk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

源码:

main.qml

  1. import QtQuick 2.0
  2.  
  3. Rectangle
  4. {
  5. id: login_gui
  6.  
  7. width: 320; height: 480
  8.  
  9. SystemPalette { id: activePalette }
  10.  
  11. //背景图片
  12. Image
  13. {
  14. id: background
  15. anchors { top: parent.top; bottom: parent.bottom }
  16. anchors.fill: parent
  17. source: "pics/pic1.png"
  18. fillMode: Image.PreserveAspectCrop
  19. }
  20.  
  21. //顶烂
  22. Item
  23. {
  24. id: top_bar
  25. width: login_gui.width; height: login_gui.height * 0.05
  26. anchors.top: login_gui.top
  27.  
  28. Text
  29. {
  30. id: title
  31. anchors { top: parent.top; horizontalCenter: parent.horizontalCenter }
  32. text: "登陆"
  33. font.bold: true
  34. font.pointSize: login_gui.height * 0.05 * 0.7
  35. color: "dark red"
  36. }
  37. }
  38.  
  39. //空白栏
  40. Item
  41. {
  42. id: space1
  43. width: login_gui.width; height: login_gui.height * 0.1
  44. anchors.top: top_bar.bottom
  45. }
  46.  
  47. //登陆框
  48. Rectangle
  49. {
  50. id: rect1
  51. width: login_gui.width * 0.8; height: login_gui.height * 0.3
  52. anchors { top: space1.bottom; horizontalCenter: parent.horizontalCenter }
  53. border.color: "#707070"
  54. color: "transparent"
  55.  
  56. LineInput
  57. {
  58. width: rect1.width * 0.8; height: rect1.height * 0.2
  59. font_size:height * 0.7
  60. anchors {horizontalCenter: rect1.horizontalCenter; top: rect1.top; topMargin: 8}
  61. hint: "请输入用户号"
  62. }
  63.  
  64. LineInput
  65. {
  66. width: rect1.width * 0.8; height: rect1.height * 0.2
  67. font_size:height * 0.7
  68. anchors {horizontalCenter: rect1.horizontalCenter; bottom: btn_login.top; bottomMargin: rect1.height * 0.1}
  69. hint: "请输入password"
  70. }
  71.  
  72. Button
  73. {
  74. id: btn_login
  75. width: rect1.width * 0.35; height: rect1.height * 0.2
  76. anchors { left: rect1.left; leftMargin: 28; bottom: rect1.bottom; bottomMargin: 8 }
  77. text: "登陆"
  78. //onClicked: SameGame.startNewGame()
  79. }
  80.  
  81. Button
  82. {
  83. id: btn_quit
  84. width: rect1.width * 0.35; height: rect1.height * 0.2
  85. anchors { right: rect1.right; rightMargin: 28; bottom: rect1.bottom; bottomMargin: 8 }
  86. text: "退出"
  87. //onClicked: SameGame.startNewGame()
  88. }
  89. }
  90. }

Button.qml

  1. import QtQuick 2.0
  2.  
  3. Rectangle {
  4. id: container
  5.  
  6. property string text: "Button"
  7.  
  8. signal clicked
  9.  
  10. width: buttonLabel.width + 20; height: buttonLabel.height + 5
  11. border { width: 1; color: Qt.darker(activePalette.button) }
  12. antialiasing: true
  13. radius: 8
  14.  
  15. // color the button with a gradient
  16. gradient: Gradient {
  17. GradientStop {
  18. position: 0.0
  19. color: {
  20. if (mouseArea.pressed)
  21. return activePalette.dark
  22. else
  23. return activePalette.light
  24. }
  25. }
  26. GradientStop { position: 1.0; color: activePalette.button }
  27. }
  28.  
  29. MouseArea {
  30. id: mouseArea
  31. anchors.fill: parent
  32. onClicked: container.clicked();
  33. }
  34.  
  35. Text {
  36. id: buttonLabel
  37. anchors.centerIn: container
  38. color: activePalette.buttonText
  39. text: container.text
  40. }
  41. }

LineInput.qml

  1. import QtQuick 2.0
  2.  
  3. FocusScope {
  4. id: wrapper
  5.  
  6. property alias text: input.text
  7. property alias hint: hint.text
  8. property alias prefix: prefix.text
  9. property int font_size: 18
  10.  
  11. signal accepted
  12.  
  13. Rectangle {
  14. anchors.fill: parent
  15. border.color: "#707070"
  16. color: "#c1c1c1"
  17. radius: 4
  18.  
  19. Text {
  20. id: hint
  21. anchors { fill: parent; leftMargin: 14 }
  22. verticalAlignment: Text.AlignVCenter
  23. text: "Enter word"
  24. font.pixelSize: font_size
  25. color: "#707070"
  26. opacity: input.length ? 0 : 1
  27. }
  28.  
  29. Text {
  30. id: prefix
  31. anchors { left: parent.left; leftMargin: 14; verticalCenter: parent.verticalCenter }
  32. verticalAlignment: Text.AlignVCenter
  33. font.pixelSize: font_size
  34. color: "#707070"
  35. opacity: !hint.opacity
  36. }
  37.  
  38. TextInput {
  39. id: input
  40. focus: true
  41. anchors { left: prefix.right; right: parent.right; top: parent.top; bottom: parent.bottom }
  42. verticalAlignment: Text.AlignVCenter
  43. font.pixelSize: font_size
  44. //color: "#707070"
  45. color: "black"
  46. onAccepted: wrapper.accepted()
  47. }
  48. }
  49. }

QML设计登陆界面的更多相关文章

  1. QML与C++交互:登陆界面设计

    QML与C++交互:登陆界面设计 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:WIN7 开发环境:Qt5.2.1 说明: QML设计前 ...

  2. WDA演练一:用户登陆界面设计(二)

    一,登陆界面设计: 1.将系统编号灰显,默认初值 2.密码栏勾选密码显示,这样就不会明文显示在页面上了: Init方法中添加默认值代码: METHOD wddoinit . DATA lo_nd_zh ...

  3. WDA演练一:用户登陆界面设计(一)

    一,新建用户表: 用户和密码参考标准的.这里给用户分了几个维度,以便后面进行接下来的业务设定. 二,新建ZLY_PORTAL 程序. 除了MAIN视图外,在添加LOGON视图. 1.导入预先做好的主页 ...

  4. Qt Quick小项目 - 登陆界面

    开发环境: win8 + Qt5.11.2 说明: 用 QML 设计一个应用的登陆界面. 效果图: 新建一个 "Qt Quick Application - empty" 工程,分 ...

  5. 一个简单WPF登陆界面,包含记住密码,自动登录等功能,简洁美观

    简介:这是一个自己以前用WPF设计的登陆界面,属于一个实验性的界面窗体,如果用于产品还很有不足.但也是有一点学习价值.后台代码略有复杂,但基本上都有注释 分类,略有代码经验的一般都能看懂. 登陆界面外 ...

  6. Android仿QQ微信开场导航以及登陆界面

    相信大家对于微信等社交应用的UI界面已经都很熟悉了,该UI最值得借鉴的莫过于第一次使用的时候一些列产品介绍的图片,可以左右滑动浏览,最后 进入应用,这一效果适用于多种项目中,相信今后开发应用一定会用得 ...

  7. 用asp连接Access数据库 制作简单登陆界面

    [题外话:最近做Internet作业,在这写一个适合初学入门的ASP连接ACCESS数据库做登陆界面的简单的例子,以慰藉我一口气把以前做过的系统中的PHP代码全改成ASP代码来临时应付作业的心情... ...

  8. WPF和Expression Blend开发实例:模拟QQ登陆界面打开和关闭特效

    不管在消费者的心中腾讯是一个怎么样的模仿者抄袭者的形象,但是腾讯在软件交互上的设计一直是一流的.正如某位已故的知名产品经理所说的:设计并非外观怎样,感觉如何.设计的是产品的工作原理.我觉得腾讯掌握了其 ...

  9. 登陆界面背景动画的css样式

    为了达到更好的用户体验,登陆界面需要设计多张背景图进行动态切换 <!doctype html> <html lang="en"> <head> ...

随机推荐

  1. shell编程备忘

    1.脚本存放目录 workspace="$(cd "$(dirname "$0")"; pwd)" 2.输出  其中 command 代表指 ...

  2. php捕获异常的处理

    try {            $result = *} catch (Exception $e) {            $result = $e; } 如果try里面报异常,$result = ...

  3. js和php判断当前是否为微信浏览器?

  4. python的exec、eval详解

    exec exec语句用来执行储存在字符串或文件中的Python语句.例如,我们可以在运行时生成一个包含Python代码的字符串,然后使用exec语句执行这些语句.下面是一个简单的例子. exec ' ...

  5. QT5-控件-QProgressBar-进度条-用来做下载进度,文件读取进度还不错

    #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QProgressBar> ...

  6. 若后台的Activity被系统回收...

    你后台的Activity被系统回收怎么办?如果后台的Activity由于某种原因被系统回收了,如何在被系统回收之前保存当前状态? 除了在栈顶的Activity,其他的Activity都有可能在内存不足 ...

  7. jquery获取浏览器高度、宽度和滚动条高度(来自网络)

    Jquery代码: alert($(window).height()); //浏览器时下窗口可视区域高度 alert($(document).height()); //浏览器时下窗口文档的高度 ale ...

  8. jQuery中的$("#my_id").html()中一点要注意的

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXcAAAA3CAIAAAB4jZ1xAAAJdUlEQVR4nO2dPU/rPBTHn2/VoVMrXZ

  9. DedeCMS中最重要的四类表

    栏目(类别): dede_arctype (dede数据库设计者认为:不管你是存放什么样的数据(软件,商品,电影..)都应该属于某个栏目(类型)) 内容主表:dede_archives (织梦数据库的 ...

  10. 深入浅出Java 重定向和请求转发的区别

    深入浅出Java 重定向和请求转发的区别 <span style="font-family:FangSong_GB2312;font-size:18px;">impor ...