views:

295

answers:

2

Hi, The following feature needs to be implemented to our existing QT & C++ application. We have to expand the user typed abbreviations into pre-defined words(s). The functionality we need to implement is something similar to text expander. Say if a user typed "FL", this needs to be replaced to "Florida" after immediately.

I was able to find out the QT documentation for capturing the key events, but I'm not sure how to modify the keyboard input with pre-defined characters set.

It would be great if you guys provide me some sample code and directions on this.

Thanks in advance!

A: 

Why do you need to modify "keyboard input"? Let the user type in, and after each character check for matches against your DB of abbreviations. Once you hit something, delete the abbreviation the user has typed and replace it with the expansion.

Given that the user types into some kind of line-edit or text box, these are very simple operations that don't even have to act on events, but merely on signals sent by these widgets when new characters are entered.

Eli Bendersky
I meant to say, to replace the user typed characters into pre-defined words. That's not text box actually, it's kind of form like IDE for code editor.
Thi
So you don't want to show what the user has typed in? I think you should - otherwise what will you display if he hasn't typed in one of the abbreviations? In any case, to hide his typing you can catch the key event and not pass it on, then do whatever you with with the data
Eli Bendersky
There will not be any rules on number of abbreviations, they can define whatever pre-defined texts with a abbreviation tag. That's up to user decision, either they can use abbreviation tag to expand or they can simply type it. Will it possible in QT?
Thi
@Thi: if so, use the original advice I provided in the answer.
Eli Bendersky
A: 

Hey,

Could this example be useful to you ?

They use a mecanism called completer, that provides different words for a given entry... It's quite like a dictionnary on a cell phone...

Custom Completer Example :

http://qt.nokia.com/doc/4.6/tools-customcompleter.html

Hope it helps a bit !

Andy M
Thanks Andy for your link. I just want to replace the pre-defined words completely with user typed abbreviation. I don't need drop down list and all. Say I can use a special key to tell my application it is a abbreviation and look up pre-defined words if any match.For an example if user pressed "fl" and space key, the application needs to replace the pre-defined words over "fl".
Thi
Hey again, yeah but knowing that you can match "fl" with "Florida", you can change the example's behavior to react to the space bar, and to add the word right away...
Andy M
Hey, did you find a solution to your problem ? How did you do ?
Andy M