Python 在qml中查找并更改属性
我有两个文件,一个是我的主python脚本,代码如下所示:Python 在qml中查找并更改属性,python,qt,pyqt,qml,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__':
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_())
ApplicationWindow {
objectName: "window"
id: window
width: 830
height: 600
color: "white"
}
我想更改qml文件中某个值的属性,代码段如下所示:
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_())
ApplicationWindow {
objectName: "window"
id: window
width: 830
height: 600
color: "white"
}
我想更改“color”属性,但如何更改?我找到了另一个带有QDeclarativeView的线程,但这不适用于我,因为我使用了上面的代码。我将PyQt5与QtQuick 2.0一起使用
~pixl2列出了库存方法;另一种方法是使用Qt元对象机制在根QML场景对象(应用程序窗口)上设置“颜色”属性。