한국어
파이썬
 

먼저 Python 및 PySide2등이 설치 되어 있어야한다. 다음의 Qt for Python 공식문서에 설치방법등이 자세히 나와있다.

https://doc.qt.io/qtforpython/contents.html

 

Qt Creator에서 Qt for Python - Empty를 선택

New Project Qt for Python.png

 

QML예제 소스코드는 특별히 다르지않다.

Window.qml

import QtQuick 2.11
import QtQuick.Window 2.11

Window {
    title: "PySide & QML"
    width: 320
    height: 240
    visible: true

    Column{
        anchors.centerIn: parent
        Image{
            source: "Py-128.png"
            anchors.horizontalCenter: parent.horizontalCenter
        }

        Text {
            id: hello
            text: qsTr("PySide2")
            font.pixelSize: 25
            horizontalAlignment: Text.AlignHCenter
            anchors.horizontalCenter: parent.horizontalCenter
        }
    }
}

 

PySide2 관련 모듈을 import 시켜주고 QmlEngine객체 생성 후 Window.qml을 로드한다. (C++과 다르지 않다.)

main.py 예제 코드

# This Python file uses the following encoding: utf-8
import sys
from os.path import *
from PySide2.QtCore import QObject
from PySide2.QtWidgets import QApplication
from PySide2.QtQml import *

if __name__ == "__main__":
    app = QApplication([])
    engine = QQmlApplicationEngine()
    dir = dirname(__file__)
    qmlFile = join(dir, 'Window.qml')
    engine.load(abspath(qmlFile))
    sys.exit(app.exec_())

 

Qt Creator의 Run을 클릭하면 윈도우가 보여진다.

pyside2+qml.png

번호 제목 글쓴이 날짜 조회 수
24 파이썬으로 작성된 소스를 py2exe을 이용하여 윈도우 응용프로그램 빌드시 콘솔창 숨기기 pjk 2014.07.29 7600
23 Python으로 작성된 프로그램을 윈도우응용프로그램(exe)으로 빌드하기 file pjk 2014.08.03 8096
22 [PyQt4]윈도우창에 별 찍기 예제 file pjk 2014.08.19 8144
21 다른 디렉터리의 파일(모듈) import 하기 pjk 2014.08.22 4697
20 [PyQt4]폴더 또는 파일을 드레그하여 그 경로를 LineEdit로 가져오기 file pjk 2014.08.22 13561
19 [PyQt4]마우스 클릭 이벤트 예제 코드 pjk 2014.08.26 6789
18 [PyQt4]multiprocess 예제 코드 pjk 2014.08.26 8167
17 [PyQt4]스레드 및 ProgressBar 예제 코드 file pjk 2014.08.26 8267
16 Python 문자열 관련 함수 레퍼런스 pjk 2014.08.29 6813
15 [PyQt4]여러가지 버튼 예제 file pjk 2014.08.29 14012
14 [PyQt4]개발 프로그램 버전표시 메세지 박스 pjk 2014.09.02 7774
13 How to Use Freeze pjk 2014.09.06 4841
12 우분투에 Python새 버전 설치 사용법 pjk 2015.02.10 3271
11 외부 프로그램 실행 pjk 2015.02.10 15393
10 print를 로그파일로 생성하기 (log출력 Redirection) makersweb 2015.03.18 5726
9 Python + QML with PyQt4 makersweb 2015.03.24 7983
8 [pyqt4]QTimer 예제 - 버튼을 누르면 3초후 함수 또는 메소드 호출 makersweb 2015.04.01 9837
7 QML 및 Window 투명처리 file makersweb 2015.04.22 4126
6 [Python]EXE또는 DLL파일의 버전정보를 알아내기위한 몇가지 방법 makersweb 2015.06.25 8811
5 Boost Python을 이용하여 python을 위한 C++ API 바인딩 [5] file makersweb 2017.01.08 9276