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
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip
Accepted Solution

Select text in TextArea based on user input ?

I need to select(highlight) existing text that is present in TextArea based on users choice i.e SystemPrompt is shown where user enters desired text and if that text is currently present in TextArea, highlight it, otherwise display additional info. Something like Find function in standard notepad application. 

 

I can't find what I'm looking for in TextEditor.

Developer
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: Select text in TextArea based on user input ?

bump
Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Select text in TextArea based on user input ?

Hi! There's setSelection(int start, int end) method in TextEditor. Have you tried using it?

Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: Select text in TextArea based on user input ?

I saw that, but how to obtain the location(start and end position) of string that the user is searching for ?

Seems that there is no some more efficient way as in plain Qt :smileysad:
Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Select text in TextArea based on user input ?

TextArea's text can be accessed using text property.

If you can access the text typed by user then the indexes can be easily calculated. Something like this (untested):

 

QString textAreaText = textArea->text();
QString userInput = ...;

int startIndex = textAreaText.indexOf(userInput, 0, Qt::CaseInsensitive);
int endIndex = startIndex + userInput.length();

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: Select text in TextArea based on user input ?

ATM the only reasonable solution (not the perfect one), but it works.

 

In QML if somebody needs it

 

var start = textArea.text.indexOf(inputFieldTextEntry())
var end = start + inputFieldTextEntry().length                
textArea.editor.setSelection(start,end)