2
は、ここに私のテストAPPのコードです:QML TextAreaの色を動的に変更する方法は?
TextAreaStyle{
id: loggerStyle
textColor: "#00ff88";
backgroundColor: "#000000";
}
TextArea {
id: taLog
readOnly: true
width: parent.width
height: parent.height - labelTitle.height - btnTest.height - 2*v_AIR
x: 0
y: labelTitle.height + v_AIR
style: loggerStyle
font.family: "Helvetica";
font.pointSize: 16;
font.bold: true
function logError(msg){
loggerStyle.textColor = "#FF0000"
taLog.text = taLog.text + "\n" + msg
}
function logMessage(msg){
loggerStyle.textColor = "#FFFFFF"
taLog.text = taLog.text + "\n" + msg
}
function logSuccess(msg){
loggerStyle.textColor = "#00FF00"
taLog.text = taLog.text + "\n" + msg
}
}
私はこのコードを実行しようとすると、私はこれらのメッセージのすべてを取得:
file:///opt/Qt5.7.0/5.7/gcc_64/qml/QtQuick/Controls/Private/Style.qml:52: ReferenceError: __control is not defined
file:///opt/Qt5.7.0/5.7/gcc_64/qml/QtQuick/Controls/Styles/Base/ScrollViewStyle.qml:56: ReferenceError: __control is not defined
file:///opt/Qt5.7.0/5.7/gcc_64/qml/QtQuick/Controls/Styles/Base/TextAreaStyle.qml:80: TypeError: Cannot read property 'enabled' of null
file:///opt/Qt5.7.0/5.7/gcc_64/qml/QtQuick/Controls/Styles/Base/TextAreaStyle.qml:77: TypeError: Cannot read property 'enabled' of null
file:///opt/Qt5.7.0/5.7/gcc_64/qml/QtQuick/Controls/Styles/Base/TextAreaStyle.qml:68: ReferenceError: __control is not defined
file:///opt/Qt5.7.0/5.7/gcc_64/qml/QtQuick/Controls/ScrollView.qml:354: TypeError: Cannot read property 'padding' of null
file:///opt/Qt5.7.0/5.7/gcc_64/qml/QtQuick/Controls/ScrollView.qml:353: TypeError: Cannot read property 'padding' of null
file:///opt/Qt5.7.0/5.7/gcc_64/qml/QtQuick/Controls/ScrollView.qml:352: TypeError: Cannot read property 'padding' of null
file:///opt/Qt5.7.0/5.7/gcc_64/qml/QtQuick/Controls/ScrollView.qml:351: TypeError: Cannot read property 'padding' of null
file:///opt/Qt5.7.0/5.7/gcc_64/qml/QtQuick/Controls/TextArea.qml:906: TypeError: Cannot read property '__selectionHandle' of null
file:///opt/Qt5.7.0/5.7/gcc_64/qml/QtQuick/Controls/TextArea.qml:942: TypeError: Cannot read property '__cursorHandle' of null
をノースタイルが私のテキスト領域に適用されません。
TextAreaにメッセージを書き込むために使用する色を動的に変更する正しい方法は何ですか?
['textColor'](http://doc.qt.io/qt-5/qml-qtquick-controls-textarea.html#textColor-prop)を直接変更しないのはなぜですか? – skypjack
です。しかし、私はTextAreaStyleを使用する必要がありますので、私はそれを使用していたTextAreaのスタイリングを読んだ。いずれかの方法。 textColorを変更すると、すべてのテキストの色が変更されます。 HMTLのリッチテキストがその答えでした。 – aarelovich