Qt第五十五章:Qt Design Studio设计登录页并打包到python运行

目录

一、Qt Design Studio

二、导出所有文件到QRC(不要改动默认的QRC文件名称)

三、QRC转换成py

1.删除Constants.qml中的

2.将App.qml和Screen01.qml中的

3.转换

4、将QRC文件和转换后的py文件,复制到python项目中使用。


一、Qt Design Studio



/*
This is a UI file (.ui.qml) that is intended to be edited in Qt Design Studio only.
It is supposed to be strictly declarative and only uses a subset of QML. If you edit
this file manually, you might introduce QML code that is not supported by Qt Design Studio.
Check out https://doc.qt.io/qtcreator/creator-quick-ui-forms.html for details on .ui.qml files.
*/
import QtQuick 6.2
import QtQuick.Controls 6.2
import UntitledProject

Rectangle {
    width: Constants.width
    height: Constants.height

    color: Constants.backgroundColor
    scale: 1
    AnimatedImage {
        id: v233ef8aa204a741d9472bfe93b618bbd5_b
        x: 0
        y: 0
        source: "images/v2-33ef8aa204a741d9472bfe93b618bbd5_b.gif"
        fillMode: Image.PreserveAspectFit

        Button {
            id: button_login
            width: 200
            height: 30
            text: qsTr("登录")
            anchors.verticalCenter: textInput_password.verticalCenter
            font.wordSpacing: 0
            font.pointSize: 12
            font.bold: true
            anchors.verticalCenterOffset: 80
            //水平居中
            anchors.horizontalCenter: parent.horizontalCenter
            //内边距
            rightPadding: 0
            bottomPadding: 0
            leftPadding: button_login.pressed?2:0
            topPadding: button_login.pressed?2:0
            //点击事件
            onClicked: console.log("点击了")

            //重写Rectangle来设置背景
            background: Rectangle  {
                //透明度
                opacity: 0.3
                //圆角
                radius: 20
                //抗锯齿
                antialiasing: true
                //边框宽度
                border.width: button_login.pressed?3:1
                //边框颜色
                border.color: button_login.pressed?"blue":"#ffffff"
                //背景颜色
                color: {
                    if (button_login.pressed|button_login.hovered) {
                        //悬停或按下状态颜色
                        Qt.rgba(0,0,0,100)
                    } else {
                        //静态颜色
                        "#ffffff"
                    }
                }
            }
            //重写Text来设置字体颜色
            contentItem:Text {
                text: button_login.text
                color: button_login.pressed|button_login.hovered?"white":"black"
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }
        }

        TextField {
            id: textInput_username
            //悬停或获取焦点 放大输入框
            width: textInput_username.activeFocus|textInput_username.hovered?205:200
            height: textInput_username.activeFocus|textInput_username.hovered?35:30
            anchors.verticalCenter: textInput_password.verticalCenter
            font.pixelSize: 12
            //字体白色
            color: 'white'
            placeholderText: "账号"
            anchors.verticalCenterOffset: -50
            anchors.horizontalCenterOffset: 0
            //水平居中
            anchors.horizontalCenter: textInput_password.horizontalCenter
            //重写Rectangle设置背景
            background: Rectangle  {
                //透明度
                opacity: 0.3
                //圆角
                radius: 20
                //抗锯齿
                antialiasing: true
                //边框宽度
                border.width: textInput_username.activeFocus?2:0
                //边框颜色
                border.color: textInput_username.activeFocus?"blue":"#ffffff"
            }

        }

        TextField {
            id: textInput_password
            //悬停或获取焦点 放大输入框
            width: textInput_password.activeFocus|textInput_password.hovered?205:200
            height: textInput_password.activeFocus|textInput_password.hovered?35:30
            anchors.verticalCenter: parent.verticalCenter
            font.pixelSize: 12
            //字体白色
            color: 'white'
            placeholderText: "密码"
//            placeholderTextColor: "black"
            echoMode: "Password"
            //水平居中
            anchors.horizontalCenter: parent.horizontalCenter
            //重写Rectangle 设置背景
            background: Rectangle  {
                //透明度
                opacity: 0.3
                //圆角
                radius: 20
                //抗锯齿
                antialiasing: true
                //边框宽度
                border.width: textInput_password.activeFocus?2:0
                //边框颜色
                border.color: textInput_password.activeFocus?"blue":"#ffffff"
            }

        }
    }
}

 

二、导出所有文件到QRC(不要改动默认的QRC文件名称)

三、QRC转换成py

将导包换成导入qrc资源:

1.删除Constants.qml中的

import QtQuick.Studio.Application
property StudioApplication application: StudioApplication {
    fontPath: Qt.resolvedUrl("../../content/" + relativeFontDirectory)
}

2.将App.qml和Screen01.qml中的

import UntitledProject换成下面(注意:冒号前的qrc不能少,用英文单引号包起来)
import 'qrc:/imports/UntitledProject'

3.转换

4、将QRC文件和转换后的py文件,复制到python项目中使用。

import sys

from PySide6.QtCore import QObject, Slot
from PySide6.QtQml import QQmlApplicationEngine
from PySide6.QtQuick import QQuickItem
from PySide6.QtWidgets import QApplication
import UntitledProject_rc


# 槽函数类(一个承载槽函数的容器类)
class Slots(QObject):
    def __init__(self, objects):
        self.objects = objects
        super().__init__()

    @Slot(str, result=None)
    def set_text_msg(self, msg):
        # 获取qml中的Text对象
        child = self.objects[0].findChild(QQuickItem, "text1")
        # 获取对象属性
        p = child.property("text")
        # 设置对象属性
        child.setProperty("text", p + msg)

    @Slot(result=str)
    def get_text_msg(self):
        return "皎氯"


"""
这种方式是以Qml作为窗口来使用。所有的逻辑UI都由Qml来完成。python提供可以调用数据的API即可。
"""


class LoginQuickWidget:
    def __init__(self):
        # 初始化UI
        self.engine = QQmlApplicationEngine()
        # 加载qml文件
        self.engine.load(u":/content/App.qml")
        if not self.engine.rootObjects():
            sys.exit(-1)
        # qml对象集合
        objects = self.engine.rootObjects()
        # 实例化槽函数
        self.slots = Slots(objects)
        # 注入槽函数
        self.engine.rootContext().setContextProperty('slots', self.slots)


if __name__ == '__main__':
    app = QApplication([])
    quick_widget = LoginQuickWidget()
    app.exec()

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
软件名称:GUI Design Studio V2.0.47.0 汉化版 官方主:http://www.carettasoftware.com 原版下载:(不需要) 运行环境:Win 9x/NT/2000/XP 软件性质:共享 汉化文件:GUIDesignStudio_R047_Setup.EXE 汉化作者:李俊富 汉化日期:2006-08-01 【软件简介】 GUI Design Studio 是一款可不须经由任何编制程序或 scripting 便可迅速地创造出 Microsoft Windows 图形用户界面设计的软件。是软件规划设计开发的一款不可多得的辅助工具。强烈推荐! 【致谢】 本人还是个汉化初哥,这款软件采用了国外破解网站下载的破解主程序。由于脱壳后资源文件重建有问题,经PASSOLO 6汉化后程序无法正常运行,后在“Windows 汉化技术”论坛求助,在论坛的兄弟姐妹们的帮助下问题得以解决,终于推出本汉化版。 对于 乾、CxLrb、决斗、东东5712 等大侠的帮助表示感谢,特别感谢 cao_cong 版主帮助修复主程序的资源文件! 【备注】 本软件汉化主要目的是自用,加之练手,所以软件中肯定存在汉化翻译问题忘勿见笑。虽然本着尽量汉化的原则但快速指南(What's this)还是没有汉化,主要是汉化工作量比较大和汉化后调整显示美观比较耗时,本人手中还有一个软件开发项目急需完成,所以该部分工作就请见谅。由于涉及软件设计,里面的许多专业术语(如控件名称)的中文翻译(平时都用英语表示,开发工具帮助文档中大部分也是英文名称)还望大家指正。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

文子阳

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值