btzs
btzs

Reputation: 1108

Qt QML state change has no effect on GUI

i have a problem with a qml state having no effect. So the state has successfully changed, but the the changes, which the statechange should change, don't happen. I'll explain the situation in detail:

i have a ListView, containing several "GameElem":

 ListView
 id: gameList
      Component{
           id: gameDelegate
           GameElem{
                gameID: pid
                gameName: name
                gameSize: size
                downloadProgress: progress
                downloadSpeed: speed
                downloadState: filestate
           }
      }
      model: gameListModel
      delegate: gameDelegate
 }

I'm emitting a signal in a class and to change the enabled buttons. So if the state is changed to "download" the "Stop download"-Button should be enabled.

 onSignalNowDownloading: {
      for( var i = 0; i < gameListModel.count ; i++)
      {
           if( gameListModel.get( i ).pid == gameID )
           {
                console.log( "Now downloading " + gameID )
                console.log( gameListModel.get( i ).filestate + " here" ) //this line
                gameListModel.setProperty( i, "filestate", "downloading")
                console.log( gameListModel.get( i ).filestate + " here" ) //and this line 
           }
      }
 }

and the log in the marked lines is "resuming here" and "downloading here". so the state is changed successfully but has no effect.

some lines earlier i do a similar thing but without state. there i'm changing the progressbar and this is working properly.

 onSignalDownloadProgress: {
      //update list data model to make the progress bar move
      for( var i = 0; i < gameListModel.count ; i++)
      {
           if( gameListModel.get( i ).pid == gameID)
           {
                gameListModel.setProperty( i, "progress", received / total)
                gameListModel.setProperty( i, "speed", speed)
                gameListModel.setProperty( i, "progressText", progress)
           }
      }
 }

this is how my state looks like. just hiding or showing several buttons.

 states: [
      State {
           name: "downloading"
           PropertyChanges {
                target: myBtnDownload
                visible:false
           }
           PropertyChanges {
                target: myBtnStop
                visible:true
           }
           PropertyChanges {
                target: myProgressBar
                visible:true
           }
           PropertyChanges {
                target: myTextSpeed
                visible: true
           }
           PropertyChanges {
                target: myBtnRun
                visible:false
           }
           PropertyChanges {
                target: myBtnFolder
                visible:false
           }
      },
      State {
           name: "resuming"
           PropertyChanges {
                target: myBtnDownload
                visible:false
           }
           PropertyChanges {
                target: myBtnStop
                visible:true
           }
           PropertyChanges {
                target: myProgressBar
                visible:true
           }
           PropertyChanges {
                target: myTextSpeed
                visible: false
           }
           PropertyChanges {
                target: myBtnRun
                visible:false
           }
           PropertyChanges {
                target: myBtnFolder
                visible:false
           }
           PropertyChanges {
                target: myBtnResume
                text: "resuming"
                visible:true
                enabled: false
           }
      }
 ]

can anyone explain me, why the progressbar changes successfully and the buttons (= states) not? maybe i can force any kind of redrawing?

thanks for your help.

Testerrrr

Upvotes: 0

Views: 928

Answers (1)

Sergei Eliseev
Sergei Eliseev

Reputation: 171

From the sample given, looks like you're changing model's filestate property instead of delegate's state. See this line:

gameListModel.setProperty( i, "filestate", "downloading")

Do you have GameElem.state bound to GameElem.downloadState? It's not in the code provided. And it is not clear in what component you have states...

Upvotes: 1

Related Questions