找到属性并在qml中更改它

时间:2014-12-14 14:20:18

标签: python qt pyqt qml

我有两个文件,一个是我的主要python脚本,代码如下:

import PyQt5
import sys
import os

from PyQt5 import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtQml import *
from PyQt5.QtQuick import *
from PyQt5.QtWidgets import *

if __name__ == '__main__':
    app = QApplication(sys.argv)
    engine = QQmlApplicationEngine()
    ctx = engine.rootContext()
    ctx.setContextProperty("main", engine)
    engine.load('qml/app.qml')
    win = engine.rootObjects()[0]

    # TODO: read language bundles

    # global variables for colors
    baseColor_color = '' # The baseColor
    openFilesListBackground_color = '' # The openFilesList background color
    textColor_color = '' # The base textColor

    _baseColor = open( '../.pybox-config/Colors/baseColor.color', "r" )
    _openFilesListBg = open( '../.pybox-config/Colors/openFilesListBackground.color', "r" )
    _textColor = open( '../.pybox-config/Colors/textColor.color', "r" )
    for line in _openFilesListBg:
        openFilesListBackground_color = line
    _openFilesListBg.close()
    for line in _baseColor:
        baseColor_color = line
    _baseColor.close()
    for line in _textColor:
        textColor_color = line
    _textColor.close()
    print("Base color is: " + baseColor_color)
    print("OpenFilesList background color is: " + openFilesListBackground_color)
    print("Text color is: " + textColor_color)


    win.show()
    sys.exit(app.exec_())

我想在qml文件中更改值的属性,该代码段如下所示:

ApplicationWindow {
    objectName: "window"
    id: window
    width: 830
    height: 600
    color: "white"
}

我想改变颜色'财产,但我怎么能这样做?我找到了QDeclarativeView的另一个帖子,但这对我没有用,因为我使用上面的代码。我将PyQt5与QtQuick 2.0一起使用。

〜pixl2

0 个答案:

没有答案