This forum has been archived. All content is frozen. Please use KDE Discuss instead.

QML in a plasmoid not changing state

Tags: None
(comma "," separated)
Vladm
Registered Member
Posts
1
Karma
0
I have an old plasmoid I wrote a few years back, which does not work with current Plasma.

After troubleshooting I come up with a test snippet below. Turns out different states have no effect(showing default gray color all the time). I tested the same code in a native Qt application written in QtCreator and it works perfectly there, changing background colors on timer event. So it somehow relates to KDE internals.

I ran it in plasmoidviewer, plasmawindowed and directly on the plasma panel with the same results. Any thoughts where to look to solve this?

Code: Select all
import QtQuick 2.2
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasmoid 2.0

Item {
    id: root
    Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
    Plasmoid.compactRepresentation:             
Rectangle {
  id: signal
  width: 200; height: 200
  color: "gray"
  state: "NORMAL"

  states: [
    State {
      name: "NORMAL"
      PropertyChanges { target: signal; color: "green"}
    },
    State {
      name: "CRITICAL"
      PropertyChanges { target: signal; color: "red"}
    }
  ]

  Timer {
    interval: 1000; running: true; repeat: false;
    onTriggered: {
      signal.state = "CRITICAL";
    }
  }
}
}
tilorenz
Registered Member
Posts
1
Karma
0
OS
Hi, I just ran into the same issue. You can solve this by putting the part with the states (your Rectangle) into a separate file, like this:
main.qml:
Code: Select all
import QtQuick 2.2
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasmoid 2.0

Item {
   id: root
   Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
   Plasmoid.compactRepresentation: SignalRect { }
}


SignalRect.qml:
Code: Select all
import QtQuick 2.2
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasmoid 2.0

Rectangle {
   id: signal
   width: 200; height: 200
   color: "gray"
   state: "NORMAL"
   
   states: [
      State {
         name: "NORMAL"
         PropertyChanges { target: signal; color: "green"}
      },
      State {
         name: "CRITICAL"
         PropertyChanges { target: signal; color: "red"}
      }
   ]
   
   Timer {
      interval: 1000; running: true; repeat: false;
      onTriggered: {
         signal.state = "CRITICAL";
      }
   }
}


I have no idea why it doesn't work in the main file or why it does work like this, though.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]