Okay, so I have this simple code that takes the property 'Text' of the object 'button_name' and modifies it. It does work , but only if the view(ApplicationWindow /engine) is active/focused and only if I move the mouse around. If the view is out of focus or the mouse isn't hovering over the application, the text doesn't Update on the screen. (tried it with other properties like 'visible' and it acts the same way.
import sys
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtCore import QObject, QUrl
if __name__ == '__main__':
sys.argv += ['--style', 'material']
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine('basic.qml')
button = engine.rootObjects()[0].findChild(QObject, "button_name")
button.setProperty('text','New_Button_Text')
sys.exit(app.exec_())
And the basic.qml:
import QtQuick 2.0
import QtQuick.Controls 2.1
import QtQuick.Controls.Material 2.1
ApplicationWindow {
visible: true
width: 200
height: 400
Material.theme: Material.Light
Material.accent: Material.Orange
Column {
anchors.centerIn: parent
Button {
objectName: "button_name"
width: 200; height:50;
font.capitalization: Font.MixedCase
text: qsTr("Button Name")
highlighted: true
Material.background: Material.Orange
}
}
}
I did found "dataChanged()" but it doesn't seem to work for QQmlApplicationEngine,and I was looking into clearComponentCache() but that didn't do anything either.
I've also tried adding onTextChanged: console.log("Text has changed to:", text)
to the Button and nothing gets printed(even after the text is updated in the view)
Also I can't access the property 'Material.background' of the Button(it returns NoneType) ,but I can access all of it's other properties.