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
Highlighted
Developer
Posts: 123
Registered: ‎09-18-2013
My Device: Dev Alpha B
My Carrier: BSNL INDIA
Accepted Solution

Change the default font

hi, I know that the font used in apps is Slate Pro. I want to change all the controls in my app to use another font, say Myriad Pro. How would I  do that? I'm coding in C++, so it would be better  if you could give me C++ specific instructions.

Developer
Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: Change the default font

[ Edited ]

Look at TextStyleDefinition and FontFaceRule. Create a global instance with custom font etc....

and then set it to all Label textStyle

https://developer.blackberry.com/native/reference/cascades/bb__cascades__fontfacerule.html

 

EDIT

Or if you want to use fonts which is already available in BlackBerry native. Then just create a Label instance with specific fontFamily



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Developer
Posts: 123
Registered: ‎09-18-2013
My Device: Dev Alpha B
My Carrier: BSNL INDIA

Re: Change the default font

Hi, thanks for the reply. But it seems like its QML specific. Could you please make it clear how to do it in c++?
Developer
Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: Change the default font

Just create your own instance inherited by Label.

For example (very simple example Smiley Wink)

mylabel.h

#ifndef MYLABEL_H_
#define MYLABEL_H_

#include <bb/cascades/Label>

using namespace bb::cascades;

class MyLabel : public Label
{
public:
    MyLabel();
    virtual ~MyLabel();
};

#endif /* MYLABEL_H_ */

 mylabel.cpp

#include "mylabel.h"

MyLabel::MyLabel()
{    
    textStyle()->setFontFamily("available font family");
}

MyLabel::~MyLabel() {
}

 and then use this class instead of using Label class;

MyLabel *label = new MyLabel; //
label.setText("example");

 Hope it helps Smiley Wink

 

PS: This is very simple example. You can play with custom functions etc....of course

 



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Developer
Posts: 123
Registered: ‎09-18-2013
My Device: Dev Alpha B
My Carrier: BSNL INDIA

Re: Change the default font

No, I want to use a font that is not present by default in the os. I have to add the .ttf file in the assets right? What do I do after that so that I can it in a textstyle?

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Change the default font

My preference would be to subclass the TextStyle rather then the whole Label or just define your own global TextStyles, that way you are not just limited to using it in Labels.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 123
Registered: ‎09-18-2013
My Device: Dev Alpha B
My Carrier: BSNL INDIA

Re: Change the default font

No, I still dont understand how I can use a custom font, one that is not available with the os. A font that I package with my app, as the fontfamily in a textstyle?
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Change the default font

The documentation currently states that it's only possible to use rules in QML, 4th paragraph down...

 

http://developer.blackberry.com/native/reference/cascades/bb__cascades__fontfacerule.html

 

However there is nothing stopping you using a QML file in a C++ componant.

 

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 123
Registered: ‎09-18-2013
My Device: Dev Alpha B
My Carrier: BSNL INDIA

Re: Change the default font

I could use findChild() to find the textstyle from a qml document. Right?
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Change the default font

You could do but it would need to be in the Scene Graph I would just load the QML document in.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.