Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10

Loading color preference

I've built a built a list of buttons to change my text areas text color

Container {
            id: blue
            objectName: "blue"
            background: Color.Blue
            
                ImageButton{
                    onClicked:{
                        myTextArea.textStyle.color = Color.Blue}
                    }
                
                }

 But I would like to get mytextarea to remember the chosen color and i'm not entirely sure on how to do that

 

 

Please use plain text.
Developer
Developer
lew
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha

Re: Loading color preference

do you need to persist even though your textarea is destroyed or only for this instance of text area?

 

if no persistance required, use a property:

 

TextArea {
  id: myTextArea
  property color myColor: Color.Blue //set default color

  onMyColorChnaged: myTextArea.textStyle.color = myColor

  ...
}
...
ImageButton{
                    onClicked:{
                        myTextArea.myColor = Color.Blue}
                    }
                
                }

 

if it's persistance you are looking for, then i suggest you look into QSettings (you will need to connect to c++ code):

http://qt-project.org/doc/qt-4.8/qsettings.html

 

Please use plain text.
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10

Re: Loading color preference

[ Edited ]

tried setting the property as you showed however that just made the colors not change at all.

 

Looked into QSettings and what I dont understand is this

 

all the examples used in the starship settings app use sliders, radio buttons, check boxes but no button or image button.  I've noticed that neither of those (button&imagebutton) have an equvalent to checked & onchecked

 

CheckBox {
                id: uranuscanner
                text: "URANUS SCANNER"
                objectName: "uranuscanner"
                checked: _starshipApp.getValueFor(objectName, "yes") //this
                onCheckedChanged: {
                    _starshipApp.saveValueFor(uranuscanner.objectName, checked) //this
                }

 so that leads me to belive that i should change something in the c++ to get/save settings

 

void App::saveSettings(const QString &objectName, const QString &Value) //should i use &objectName
{
    // A new value is saved to the application settings object.
    QSettings settings;
    settings.setValue(objectName, QVariant(Value));

}

 should i keep QString &objectName or use something else..... if none of that makes any sense I would appreciate a chat with someone who knows more about QSettings  :smileyhappy:  (if those aren't it then the issue must be when i'm calling 

myTextArea.textStyle.Color: app.getValueFor("","") // I want these values to be my last chosen color

my over-all goal is have myTextArea use the last selected text color on the apps next startup

Please use plain text.
Developer
Developer
lew
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha

Re: Loading color preference

yes store a QString...value could be for example:

#00FF00

 

to persist color:
_starshipApp.saveValueFor("textarea.color", somecolor_in_hex) 

to retrieve color:
_starshipApp.getValueFor("textarea.color") 

to set color in QML:
myTextArea.textStyle.Color: Color.create(app.getValueFor("textarea.color"))

 QSettings is similar to a QMap/HashMap...it uses a key/value datastructure.

Please use plain text.