Quantcast
Channel: Active questions tagged qtquick2 - Stack Overflow
Viewing all articles
Browse latest Browse all 137

Dynamically change QML Theme at runtime on MouseClick

$
0
0

I have Theme1.js which has the property variables related to Theme 1 styling, Similarly like this I have for Theme 2, Theme2.jsNow in main.qml, If I click on the MouseArea, The Theme should toggle between Theme1 to Theme2. I found that conditional import Statements doesn't exist in QML. Is there any other way for this.?

Theme1.js

var color="red";var textString="This is Theme1"

Theme2.js

var color="green";var textString="This is Theme2"

main.qml

import QtQuick 2.3import QtQuick.Window 2.2import "Theme1.js" as Theme //default Theme Window {    visible: true    color:Theme.color    MouseArea {        anchors.fill: parent        onClicked: {            //Change Theme 1 to Theme 2. Basically Toggle Theme here        }    }    Text {        text: Theme.textString        anchors.centerIn: parent    }}

Viewing all articles
Browse latest Browse all 137

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>