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
Contributor
II_ARROWS
Posts: 45
Registered: ‎03-02-2012
My Device: Torch 9810
Accepted Solution

How to set keyboard layout?

Hi,

I have some textbox that accept only numbers, but I cannot find any way to force the keyboard to appear as a numeric-only layout.

I tried to change it by C++ code but as soon as I click the textbox,  it changes back to standard layout.

 

From the reference site I cannot find anything (it's the worst documentation site I've ever seen...). 

BlackBerry Development Advisor (Retired)
danielrr5
Posts: 32
Registered: ‎05-09-2012
My Device: BB10

Re: How to set keyboard layout?

[ Edited ]

Hi there, 

 

Have you tried setting the keyboard options before it is displayed?

 

virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_NUM_PUNC, VIRTUALKEYBOARD_ENTER_DEFAULT);

 

(see https://bdsc.webapps.blackberry.com/native/reference/com.qnx.doc.bps.lib_ref/com.qnx.doc.bps.lib_ref...

 

The touch event for your text area is called before the keyboard is displayed so you can call virtualkeyboard_change_options when it happens:


#include <bps/virtualkeyboard.h>

 

App::App() {

    ... 

    TextArea* myTextArea = ... // find it

    QObject::connect(myTextArea, SIGNAL(touch(bb::cascades::TouchEvent *)), this, SLOT(onTextAreaTouch(bb::cascades::TouchEvent *)));

    ...

}

 

void App:: onTextAreaTouch(bb::cascades::TouchEvent *event) {

    virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_NUM_PUNC, VIRTUALKEYBOARD_ENTER_DEFAULT);

}

 

This isn't ideal I agree. I'm sure a better solution will present itself in the near future.

Contributor
II_ARROWS
Posts: 45
Registered: ‎03-02-2012
My Device: Torch 9810

Re: How to set keyboard layout?

Does it works? To me sound like that, since the touch event is called before the keyobard appears, the keyboard would be changed back to default when it appears.

I'll try, but would be better to have an appropriate property inside text input base class. Since it's something that is often needed, as long as a max lenght.

Thanks.
BlackBerry Development Advisor (Retired)
danielrr5
Posts: 32
Registered: ‎05-09-2012
My Device: BB10

Re: How to set keyboard layout?

[ Edited ]

I've tried it and it works on my side. Let me how it goes for you, or if you have any other questions.

 

Agreed about the need for a property in the TextArea itself.

 

Cheers, 

Daniel

BlackBerry Development Advisor (Retired)
danielrr5
Posts: 32
Registered: ‎05-09-2012
My Device: BB10

Re: How to set keyboard layout?

Hey there,

 

Have you made any progress on your issue? Let me know if you need additional help or have solved the problem and want to share your insights.

 

Cheers, 

Daniel

Contributor
II_ARROWS
Posts: 45
Registered: ‎03-02-2012
My Device: Torch 9810

Re: How to set keyboard layout?

Sorry, I am working on another company project right now and I haven't tested it yet.

I will give you feedback once I've tried it.
Contributor
II_ARROWS
Posts: 45
Registered: ‎03-02-2012
My Device: Torch 9810

Re: How to set keyboard layout?

Hello, first of all, I'm not using a TextArea but a TextField...

 

I don't know what I am doing wrong, but on console I find these error:

No such slot App::Calculate(const QString &) in ../src/App.cpp:85
Object::connect:  (sender name:   'number')

 

It's not only on keyboard event, since this should be connected on change of the TextField.

 

I have an App.hpp with the correct class signature, and this is the code:

class App : public QObject
{
    App()
   {
//Load qml into *root
       this->Number1 = root->findChild<TextField*>("number1");
//[...] other get
        QObject::connect(Number1, SIGNAL(textChanging(const QString &)), this, SLOT(Calculate(const QString &)));

        QObject::connect(Number1, SIGNAL(touch(bb::cascades::TouchEvent *)), this, SLOT(onTextFieldTouch(bb::cascades::TouchEvent *)));
//other initialization
   }

   void Calculate(const QString & NewText)//Note: NewText not used
   {
//my calculations
   }

   void onTextFieldTouch(bb::cascades::TouchEvent *event)
   {
	qDebug() << "Event occoured";
	virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_NUM_PUNC, VIRTUALKEYBOARD_ENTER_DEFAULT);
   }
}

 I tried with a TextArea too, but it didn't work...

 

BlackBerry Development Advisor (Retired)
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Device: developer

Re: How to set keyboard layout?

Let's get past the connect issue first.

The usual suspect list:

1. is the connect malformed? -- looks correct to me

2. does the signature match?   (does your App have a Calculate(const QString&)

3. is the routine a slot?  (is it within a public slots:smileyhappy:

4. Is the file moc'd?

    do you have Q_OBJECT

I assume 4 is not an issue if you used a wizard to create the project or copied from another project, and because I expect we would have seen issues with the other connects first.

 

My usual error is 2.  const, perhaps?

 

(BTW, I prefer camel casing for variables: newText rather than NewText) to distinguish from types.  Also, you can omit the variable name or use Q_UNUSED macro if you are getting compiler warnings)

BlackBerry Development Advisor (Retired)
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Device: developer

Re: How to set keyboard layout?

[ Edited ]

...and I realize that's your .h file.  So it's missing the public slots:

and the Q_OBJECT

 

Stuart

Contributor
II_ARROWS
Posts: 45
Registered: ‎03-02-2012
My Device: Torch 9810

Re: How to set keyboard layout?

4: it is only in the definition of class in the .hpp; I don't think it's a problem.

2: I tried to connect it wit a "Calculation()" first but it gave me the same error so I thought the compiler wanted that the SLOT to match the SIGNAL params...

 

Sooo... I have to use "public slots" identifier... Now I got it.

I'll try.