Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Set background image after receiving signal



  • I have some code:

    import QtQuick 2.9

    ApplicationWindow {

    id: mainWindow
    visible: true
    width: 1920
    height: 1080
    flags: Qt.FramelessWindowHint
    Image {
        id: nextView
        visible: false
        source: "ChargeView.png"
    }
    background: Image {
        id: loggingImage
        source: "LoggingView.png"
    }
    Loader {
        id: chargeViewLoader
        source: "ChargeViewItems.qml"
    }
    Connections {
        target: chargeViewLoader.item
    
        onCancelSignal: {
            mainWindow.background = nextView  (*)
            console.log("Cancel");
        }
        onOkSignal: console.log("OK");
    } 
    // any other code
    

    }

    signals cancelSignal and okSignal are received form another QML file.
    When cancelSignal (line * ) is received I would like to change background image on mainWindow
    but there is only white screen



  • @Milosz Hi,

    Change only the source property of your loggingImage component:

    ApplicationWindow{
    	
    	//...
    	
    	background: Image {
    		id: loggingImage
    		source: "LoggingView.png"
    	}
    	
    	Loader {
    		id: chargeViewLoader
    		source: "ChargeViewItems.qml"
    	}
    	
    	Connections {
    		target: chargeViewLoader.item
    
    		onCancelSignal: {
    			loggingImage.source  = "ChargeView.png"
    			console.log("Cancel");
    		}
    		onOkSignal: console.log("OK");
    	} 
    	// any other code
    }
    


  • It is great!!!
    Thanks a lot,



  • @Milosz if your issue is solved, please don't forget to mark your post as such. Thanks.


Log in to reply