![]() |
Colour changing rectangle
Hi,
I have a Page, on that page is a rectangle, I can click on the rectangle and it changes colour, I'd like the last colour picked to remain when I reopen the app again. I thought I could do this with settings, but it doesn't work. It seems as soon as I introduce 'settings' into the code that the app doesn't open. I thought maybe to include 'import com.jolla.settings 1.0' but that doesn't help either, what am I doing wrong? Code:
import com.jolla.settings 1.0 |
Re: Colour changing rectangle
|
Re: Colour changing rectangle
Explore Lockscreen Analog Clock settings page.
|
Re: Colour changing rectangle
Explore documentation and stop doing random copy-paste activities without understanding how it works.
|
Re: Colour changing rectangle
Quote:
You don't like my questions?, don't fkin answer them, simples! |
Re: Colour changing rectangle
Quote:
Edit: what I mean to say is, I was hoping for more information. However, it's unreal for me, that I didn't connect the dots, just a few days ago Ancelad showed me about ConfigurationGroup, so I do have a starting place. Thanks for your input. |
Re: Colour changing rectangle
Quote:
Feel free to take it as an advice or... What documentation would that be? |
Re: Colour changing rectangle
Quote:
The documentation for sailfish doesn't give much away, fine for those who grew up with coding, got shown, learned from their dad/brother, did it at school, they already have some roots in the subject, I don't have that under my belt. The documentation as pointed out by velox, I have already looked, it really gives very little information, there is not even an example, which leads me to believe, if you are developing for Sailfish, it is assumed you already know your way round coding. Recently, Ancelad showed me a usage for ConfigurationGroup, okay cool, now I have to learn about dconf and keys, I know how to read/list/search dconf, I even learned how to remove/reset a dconf value but as yet, I'm not quite understanding about 'path' and setting its values, sometimes I need to be shown. My question about the color changing rectangle was an exercise in understanding Settings, I found it easier work with a rectangle, mouse area and a bit about color, familiar ground, easy stuff. Now I have to connect ConfigGroup to my actual code, which is about changing windspeed units, from default m/s to mph/kmh/kts by tapping on the windspeed output in sailfish weather. I lack discipline, especially when info appears to be thin on the ground...but the main thing is, I'm keen to learn about it all and I'm not going to stop doing what I'm doing despite what others think, as for reading documentation, I'm always looking at that or my device before asking questions. After all, isn't this what TMO is for? |
Re: Colour changing rectangle
Back to your question, Settings belong to Qt.labs.settings wich is not available in Sailfish, so you have to use
ConfigurationGroup, here is a sample program that should work (untested :) ) Code:
import Nemo.Configuration 1.0 variant value(string key, variant defaultValue, int typeHint) Returns the value of key as a variant. If key does not exist defaultValue will be returned. The line rect.color = settings.value("rectColor", "#000000") tries to load the value of rectColor, if that doenst exist (at the first time it wont) it will load the default value "#000000". The rest is pretty straightforward, on destruction the last rectangle color will be saved in rectColor string. While reading the docs is important, I have to agree that this particular documentation about ConfigurationGroup is very poor. Feel free to ask any more questions if something is unclear to you, and keep on coding ;) Cheers |
Re: Colour changing rectangle
Quote:
user 'velox' was also on the money, I just needed to see a working example with sailfish to get an understanding of how it works, also Ancelad guided me along a similar path recently using ConfigGroup, but for some reason, I find your example easier to follow/understand and above all, I get the outcome I wanted. I realised after searching my device, the qt.labs.settings does not exist in sailfish, so one of or at least, my main question should have been "what is the equivalent to qt.labs.settings?". With minor tweaks, the code looks like this; Code:
import QtQuick 2.0 |
All times are GMT. The time now is 21:00. |
vBulletin® Version 3.8.8