QlineEdit with Japanese characters - c++

I have a main widget in my application when I type something I display a child widget with lineEdit in it.If the input language is Japanese and I press any key then widget with line edit in it will appear with first character typed (lineEdit->setText("h")) and if I continue typing the next character should also appear. Now the issue which I am facing is that how to make the second character really "part" of the first character.
First letter is "h"
second letter is "e".
CASE 1 : When "h" is not part of "e" ,it will appear like" h エ".
CASE 2 : When h and e are combined in Japanese it looks like "ヘ".
I want to achieve case 2.
What I have tried:
Enabled the setAttribute( Qt::WA_InputMethodEnabled, true ); on my lineEdit
and also captured the QEvent::InputMethod but then I am not able to combine the first letter and subsequent letters user types.

Related

How to make QTextCursor::WordUnderCursor include more characters or larger words

I'm trying to show a tooltip when the cursor is over a keyword in a text editor using:
QTextCursor cursor = cursorForPosition(pos);
cursor.select(QTextCursor::WordUnderCursor);
This works well but the definition of a word does not fits my needs. For exemple the keyword \abcde is recognized as 2 words \ and abcde. Similarly the word a1:2 is recognized in three parts a1, : and 1. Basically what I'd like is to change the behavior such as a word is defined as a set of characters separated by space.
I tryied QTextCursor::BlockUnderCursor but it does the same than QTextCursor::LineUnderCursor and returns the entire line.

Split mixed upper and lowercase in the same word into two lines

I have a string in cells that is lacking new lines.
It looks like this:
Text Text TextText Text Text T5df Tdfcv TextNeu
In other words:
If there is a change from Lowercase to Uppercase within a word, this is where a new line should be inserted as \n.
So the example would convert to
Text Text Text
Text Text Text T5df Tdfcv Text
Neu
Resp.:
Text Text Text\nText Text Text T5df Tdfcv Text\nNeu
I found
String[] r = s.split("(?=\\p{Lu})");
I tried REGAUS(F2;"(?=\\p{Upper})";"\n";"g") yet I get a 502, as something is wrong with the regex.
Which formula do I need for calc to do this?
With english formula names, the following formula will do the trick:
=REGEX(A1;"([:lower:])([:upper:])";"$1"&CHAR(10)&"$2";"g")
Same on multiple lines for sake of readability:
=REGEX(
A1;
"([:lower:])([:upper:])";
"$1" & CHAR(10) & "$2";
"g"
)
It matches a lower-case letter followed by an upper-case letter, and inserts a newline using the CHAR() function.
You'll have to adapt the line heigth manually, otherwise you will see only "Neu" (the last line).
For localised formula names (german), it would be:
=REGAUS(A1;"([:lower:])([:upper:])";"$1"&ZEICHEN(10)&"$2";"g")
I would have expected that inserting "\n" should work, too, but i did'nt manage got get it working, thus the recourse to CHAR(10).

use correctly String#tr method?

New to Crystal-lang, I'm actually trying to code a Caesar cipher.
Problem is, when I enter a string to encode, the program show the same string without modification.
if ARGV.size < 3
puts "./caesarcipher [ed] [text] [num]"
exit
end
letter = ARGV[0]
str = ARGV[1]
n = ARGV[2].to_i
alphabet = ("A".."Z").to_a
case letter
when "e" then puts str.tr(alphabet.join, alphabet.rotate(n).join)
when "d" then puts str.tr(alphabet.join, alphabet.rotate(n * -1).join)
else puts "./caesarcipher [ed] [text] [num]"
end
Since the two arguments in the tr method contain what I want and tr must return a value, I don't understand why nothing change.
Welcome to Stack Overflow!
The reason why this didn't work for you, is because if you examine the alphabet array, it's actually only capital letters. So in your translation, you are only translating the upper case characters. If you instead change
alphabet=("a".."z").to_a
that will translate for the lower case characters.
If you want to do both, then I would suggest creating two "alphabets" one with upper and one with lower case letters, and then applying the translation twice on the string, one with upper and one with lower case alphabets.

Tkinter - Underline only letters in Labels?

a = Label(root,text='h e l l o',underline=0)
So basically I want to be able to choose which parts of the string I want to underline. Right now it only lets me choose one at a time. If I try:
a = Label(root,text='h e l l o',underline=0,1)
I get the error:
a = Label(root,text='h e l l o',underline=0,2)
SyntaxError: non-keyword arg after keyword arg
I have looked at other posts and they suggest making a font to make the whole string underlined. I want to make just the letters underlined. Is there a way to do this?
Multiple character underlining is possible with unicode '\u0332' (underline of previous character). This avoids using the underline styling of the tkinter Label widget and allows multiple items to be underlined. To make just the letters underlined, use list comprehension and isalpha() to identify the letters. In the example below, the required text is moved to a string (mylabel) and preprocessed using:
mylabel='h e l l o'
utext=''.join([letter+'\u0332' if letter.isalpha() else letter for letter in mylabel])
a = Label(root,text=utext)
The above was tested on Python 3.7 on Windows 10. Note the previous limitations identifed with using unicode '\u0332' on some platforms.
Your choice with a Label is to underline a single character with the underline option, or to underline the entire string by using a font with underline option turned on.
The text widget allows you to underline individual characters, so my recommendation is to use a single-line text widget, or to use a canvas widget with multiple text items for each group of characters that are to be underlined or not.

Select a word by cursor and get its position in Qt/C++

I have a small Qt/C++ application with a QTextEdit which uploads some text. I want to be able to select a separate word by cursor and to get its position in the text.
For example, in the following sentence: "It is a sunny day".
If I select the word 'sunny', I will get the int 4, as it is placed at the 4th position in the sentence.
How can I achieve that?
You'll have to :
Get the field's text as QString using QTextEdit::text() method
Use QTextEdit.textCursor()->selectionEnd() to know where selection ends.
Use QString::mid to get the substring from 0 to end of selection
Use QString::count to know how many spaces it contains. This will give you access to the word's position.
Something like:
textEdit.text().mid( 0, textEdit.textCursor()->selectionEnd() ).count( ' ' )+1;
Hope it helps. That's minimal, you'll probably want to deal with partial word selection or any others relevant corner case.