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
AvisDx
Posts: 101
Registered: ‎12-02-2012
My Device: Z10 LE, PlayBook 32GB
My Carrier: Beeline

Re: Change Theme - edit "bar-descriptor.xml" at runtime

I suppose, that for now we can only change color of controls manually when user wants to change theme :smileysad:



My BB10 apps: Photo Memo | TriQuick | SkidStone | MeeBirthdays
If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post.
Please use plain text.
Developer
helex
Posts: 286
Registered: ‎02-14-2012
My Device: Nokia N950 / BB Playbook
My Carrier: -

Re: Change Theme - edit "bar-descriptor.xml" at runtime

That's not a solution. Check out the App FancyTran, it's working over there. And it's not a simple change of the colors. You can't do this at stuff like Dividers an several other details. So changing of colors is not working for complex Apps.

And the App FancyTran needs also a uncomfortable restart. If this would be a simple boolean setting, why a restart?
Please use plain text.
Developer
Paratheo
Posts: 134
Registered: ‎04-25-2009
My Device: Z30
My Carrier: AT&T

Re: Change Theme - edit "bar-descriptor.xml" at runtime

I'm sure that someone here on this forum can find a solution. There must be a trick for changing theme in release build. Any ideas?

Please use plain text.
Developer
Paratheo
Posts: 134
Registered: ‎04-25-2009
My Device: Z30
My Carrier: AT&T

Re: Change Theme - edit "bar-descriptor.xml" at runtime

[ Edited ]

Through a bit of debugging, I found that in release mode, the function returns at this line

 

if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
				return; 
}

 Does this trigger any ideas?

Please use plain text.
Developer
helex
Posts: 286
Registered: ‎02-14-2012
My Device: Nokia N950 / BB Playbook
My Carrier: -

Re: Change Theme - edit "bar-descriptor.xml" at runtime

Hmm... no write access, does the file still exist at the expected place?
Please use plain text.
Developer
xnike
Posts: 59
Registered: ‎11-04-2011
My Device: PlayBook, DAC, STL100-1, STL100-2
My Carrier: MTS RUS

Re: Change Theme - edit "bar-descriptor.xml" at runtime

Sorry guys of misleading you.

The solution is really simple: all you need is to update environment variable before creating an application instance.

 

Update the main.cpp in the following way:

 

#include "Settings.hpp"

 

QString getValue(QString value) {
    Settings settings;
    return settings.getValueFor(value, "");
}

 

Q_DECL_EXPORT int main(int argc, char **argv) {
    qputenv("CASCADES_THEME", getValue("theme").toUtf8());

    Application app(argc, argv);
    new ApplicationUI(&app);

    return Application::exec();
}

 

Create Settings.cpp:

 

#include "Settings.hpp"

#include <QSettings>

Settings::smileyfrustrated:ettings() {
}

QString Settings::getValueFor(const QString &objectName, const QString &defaultValue) {
    QSettings settings;

    // If no value has been saved, return the default value.
    if (settings.value(objectName).isNull()) {
        return defaultValue;
    }

    // Otherwise, return the value stored in the settings object.
    return settings.value(objectName).toString();
}

void Settings::saveValueFor(const QString &objectName, const QString &inputValue) {
    // A new value is saved to the application settings object.
    QSettings settings;
    settings.setValue(objectName, QVariant(inputValue));
}

Settings::~Settings() {
}

 

Create Settings.hpp:

 

#ifndef SETTINGS_HPP_
#define SETTINGS_HPP_

#include <QObject>

class Settings: public QObject {
Q_OBJECT

public:
    Settings();
    virtual ~Settings();

Q_INVOKABLE
    QString getValueFor(const QString &objectName, const QString &defaultValue);

Q_INVOKABLE
    void saveValueFor(const QString &objectName, const QString &inputValue);
};

#endif

 

In your qml code you should choose one of the possible values for "theme" key( they are "bright"  and "dark") and store using the Settings instance, propagated in the applicationui.cpp.

 

Please use plain text.
Developer
xnike
Posts: 59
Registered: ‎11-04-2011
My Device: PlayBook, DAC, STL100-1, STL100-2
My Carrier: MTS RUS

Re: Change Theme - edit "bar-descriptor.xml" at runtime

Please use plain text.
Developer
yogeshwarp
Posts: 30
Registered: ‎11-09-2012
My Device: Dev Alpha A
My Carrier: Airtel

Re: Change Theme - edit "bar-descriptor.xml" at runtime

Looks like the env variable setting before creating application instance fails to work in few cases (as per user reports) e.g. on Z10 it shows default light/bright theme even though user has selected dark. any known issues with this approach?

Please use plain text.
New Contributor
danielsanfr
Posts: 2
Registered: ‎11-14-2013
My Device: Z10
My Carrier: TIM

Re: Change Theme - edit "bar-descriptor.xml" at runtime

Many thanks for the tip man, worked perfectly for me!

Please use plain text.