【PyQT5+QML】18行代码实现Hello World入门

栏目: C++ · 发布时间: 6年前

内容简介:首先创建一个python文件,说明:然后创建qml文件:

首先创建一个 python 文件, test.py :

from PyQt5.QtGui import QGuiApplication  
from PyQt5 import QtQml  
if __name__ == '__main__':  
    path = 'qml/test.qml'
    app = QGuiApplication([])
    engine = QtQml.QQmlApplicationEngine()
    engine.load(path)
    app.exec_()

说明:

app = QGuiApplication([])
QtQml.QQmlApplicationEngine()
engine.load(path)
app.exec_()

然后创建qml文件:

import QtQuick 2.3  
import QtQuick.Controls 1.2  
ApplicationWindow {  
    id: test
    visible: true
    width: 100; height: 100
    Text {
        text: "hello world!";
    }
}

说明:

  1. visible: true 是必须的,否则application不会显示
  2. 创建了一个 Text 组件来显示 hello world

直接运行, python test.py ,就可以看到熟悉的 hello world 了。

转载请注明出处

http://zgljl2012.com/pyqt5-qml-18xing-dai-ma-shi-xian-hello-worldru-men/


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Mobilizing Web Sites

Mobilizing Web Sites

Layon, Kristofer / 2011-12 / 266.00元

Everyone has been talking about the mobile web in recent years, and more of us are browsing the web on smartphones and similar devices than ever before. But most of what we are viewing has not yet bee......一起来看看 《Mobilizing Web Sites》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具