QML设计登陆界面

QML设计登陆界面

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

环境:

主机:WIN7

开发环境:Qt5.2

说明:

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

效果图:

源代码:

main.qml

import QtQuick 2.0

Rectangle
{
    id: login_gui

    width: 320; height: 480

    SystemPalette { id: activePalette }

    //背景图片
    Image
    {
        id: background
        anchors { top: parent.top; bottom: parent.bottom }
        anchors.fill: parent
        source: "pics/pic1.png"
        fillMode: Image.PreserveAspectCrop
    }

    //顶烂
    Item
    {
        id: top_bar
        width: login_gui.width; height: login_gui.height * 0.05
        anchors.top: login_gui.top

        Text
        {
            id: title
            anchors { top: parent.top; horizontalCenter: parent.horizontalCenter }
            text: "登陆"
            font.bold: true
            font.pointSize: login_gui.height * 0.05 * 0.7
            color: "dark red"
        }
    }

    //空白栏
    Item
    {
        id: space1
        width: login_gui.width; height: login_gui.height * 0.1
        anchors.top: top_bar.bottom
    }

    //登陆框
    Rectangle
    {
        id: rect1
        width: login_gui.width * 0.8; height: login_gui.height * 0.3
        anchors { top: space1.bottom; horizontalCenter: parent.horizontalCenter }
        border.color: "#707070"
        color: "transparent"

        LineInput
        {
            width: rect1.width * 0.8; height: rect1.height * 0.2
            font_size:height * 0.7
            anchors {horizontalCenter: rect1.horizontalCenter; top: rect1.top; topMargin: 8}
            hint: "请输入用户号"
        }

        LineInput
        {
            width: rect1.width * 0.8; height: rect1.height * 0.2
            font_size:height * 0.7
            anchors {horizontalCenter: rect1.horizontalCenter; bottom: btn_login.top;  bottomMargin: rect1.height * 0.1}
            hint: "请输入密码"
        }

        Button
        {
            id: btn_login
            width: rect1.width * 0.35; height: rect1.height * 0.2
            anchors { left: rect1.left; leftMargin: 28; bottom: rect1.bottom; bottomMargin: 8 }
            text: "登陆"
            //onClicked: SameGame.startNewGame()
        }

        Button
        {
            id: btn_quit
            width: rect1.width * 0.35; height: rect1.height * 0.2
            anchors { right: rect1.right; rightMargin: 28; bottom: rect1.bottom; bottomMargin: 8 }
            text: "退出"
            //onClicked: SameGame.startNewGame()
        }
    }
}

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
    }
}

LineInput.qml

import QtQuick 2.0

FocusScope {
    id: wrapper

    property alias text: input.text
    property alias hint: hint.text
    property alias prefix: prefix.text
    property int font_size: 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: font_size
            color: "#707070"
            opacity: input.length ? 0 : 1
        }

        Text {
            id: prefix
            anchors { left: parent.left; leftMargin: 14; verticalCenter: parent.verticalCenter }
            verticalAlignment: Text.AlignVCenter
            font.pixelSize: font_size
            color: "#707070"
            opacity: !hint.opacity
        }

        TextInput {
            id: input
            focus: true
            anchors { left: prefix.right; right: parent.right; top: parent.top; bottom: parent.bottom }
            verticalAlignment: Text.AlignVCenter
            font.pixelSize: font_size
            //color: "#707070"
            color: "black"
            onAccepted: wrapper.accepted()
        }
    }
}

QML设计登陆界面,码迷,mamicode.com

时间: 2024-08-29 20:09:48

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

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

本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明.   环境: 主机:WIN7 开发环境:Qt5.2.1 说明: QML设计前台界面,C++后台负责逻辑 效果图: 源代码:   前台qml文件 login.qml [javascript] view plain copy /********************************************************************* *                    

登陆界面(二)(转)

原文转自 https://blog.csdn.net/jdh99/article/details/25774797 环境: 主机:WIN7 开发环境:Qt5.2.1 说明: QML设计前台界面,C++后台负责逻辑 效果图: 源代码:  前台qml文件 login.qml /********************************************************************* * 登陆界面qml文件 * (c)copyright 2014,jdh * All R

iOS设计中不同屏幕适配的方法-登陆界面

在iOS的手机界面设计中,由于不同手机类型的手机的尺寸不同,那么在设计手机界面时就得对屏幕进行适配,这里就以登陆界面的设计为例简单说明下 实现屏幕适配的方法:(屏幕自动适配缩放) 效果: 下面就看下代码实现的过程: 1.在代理中实现的代码: AppDelegate.h // 登陆界面设计 #import <UIKit/UIKit.h> #define ScreenHeight [[UIScreen mainScreen]bounds].size.height//屏幕高度 #define Scr

java web程序 上机考试登陆界面设计实现

今天是java web上机.做一个登陆注册的界面.要求:jsp.mysql数据库,js做一个美观的界面.功能.可以添加 更多啊.我做的界面被老师狠狠的扣了分.问题在于.当用户没有输入任何信息(没有输入用户名和密码)就直接提交的 时候,页面显示500错误,这里改正的方案2点.我是这么想的.1.要么是提交时弹出一个对话框.显示用户名和密码为空!.这里 要注意的是,弹出的对话框不能阻止用户输入信息,弹出后,依然让用户输入.2.要么是提交按钮后依然跳转到本页面.因为一个form表单 只能跳转到一个页面,

登陆界面(一)(转)

原文转自 https://blog.csdn.net/jdh99/article/details/24711531 环境: 主机:WIN7 开发环境:Qt5.2 说明: 用QML设计一个应用的登陆界面 效果图: 源代码: main.qml import QtQuick 2.0 Rectangle { id: login_gui width: 320; height: 480 SystemPalette { id: activePalette } //背景图片 Image { id: backgr

项目前安装软件以及登陆界面(Eclipse+JDK+SDK+ADT )

 我们准备做的是一个聊天软件,所以我尝试做了一下登陆界面.本来打算用前段的技术实现,后来就做了一下子,但是没有完善.上周刚好买了本安卓的书,于是自学了一部分知识.于是自己尝试做下手机端的登陆界面. 进行安卓开发,首先是安装软件:Eclipse+JDK+SDK+ADT(虽然Android studio现在非常流行,但是我还是用eclipse配置了,感觉用习惯了eclipse) 可以直接在这里下载所有的软件:http://www.android-studio.org/ 为什么不直接进官网下载?由于某

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

不管在消费者的心中腾讯是一个怎么样的模仿者抄袭者的形象,但是腾讯在软件交互上的设计一直是一流的.正如某位已故的知名产品经理所说的:设计并非外观怎样,感觉如何.设计的是产品的工作原理.我觉得腾讯掌握了其精髓.在2013版的桌面版QQ中,腾讯的登陆界面在打开的时候有一个展开的过程,而关闭的时候有个收缩的过程.效果如图: 借助WPF和Expression Blend,我们可以轻易的实现这么一个效果,最终用比较慢的速率实现这个效果如下: 这个效果一共能够分成两个部分:展开和收缩,具体的代码如下: 收缩的

windows程序设计——飞机大战笔记(单文档文件登陆界面)

//////////////2015/07/21//////////////// /////////////by xbw/////////////////////// /////////////环境 VS 2013//////////// 飞机大战做的差不多了,闲来无事加点高大上的东西,关于单文档的登陆界面::: 界面有点丑,但是足够账号登陆了,,先试一把: 还不错吧,该有的都有了:: 下面说一下过程 ...... 首先,我们要在资源视图中创建一个Dialog对话框::: 先大体画一下这个对话框

c#做登陆界面

登陆界面最主要的就是数据库访问,这里就不多讲界面设计了, 直接给代码:(这段代码加在登陆按钮的事件里) #region 定义用户信息变量 string UserName = TextBox_User_Name.Text.Trim(); string UserPassword = TextBox_User_Password.Text.Trim(); #endregion #region 检查用户是否输入用户信息 if (UserName == "" && UserPass