Text Input from QKeyEvent not working with Russian letters in QTextDocument - qt

I have a strange problem with Text Input and Qt. I have a Widget that takes Key Press events, extracts the text and appends the text to a string variable and then creates a QTextDocument in the paint event and paints the text, so far so good, works with Latin letters. But when some users try to type non Latin letters like Russian, then some letters are are still in Latin and others are missing totally.
For example, typing this text: "Не работает на русском языке" results in this:
I'm getting the typed letters from QKeyEvent https://doc.qt.io/qt-5/qkeyevent.html#text
Any idea what causes this behavior and how to fix it?

Related

QT using QML textedit and/or textarea, how to map which index in textedit.text is mapped to formatted text

In QML TextEdit or TextArea, we can format or style a text either HTML or Markdown, the non-formatted text can be accessed by TextArea.text but the formatted text can be accessed by getFormattedText().
I want to know how to get which index in the non-formatted text is equivalent for the formatted text, this is important when say, If I select a text in the formatted view, I want to change its markdown in the non-formatted view. There seems to not have a method for this.
example, in formatted view a string with "1\n2\n3\n4" which means every line there is a text, is equivalent to "1\n\n2\n\n3\n\n" or a bold text like in formatted "text" is equivalent to "text" in non formatted.
So if I have a string "the quick brown fox" where the word "quick" is bold, it is represented in the non formated text (TextArea.text) as "the quick brown fox", now the string index of a fox is
index 16 in the formatted text but it is index 20 in the non-formatted text.
Is there an efficient way to access this?
Any idea or suggestion?

QMimeData: How to properly copy formatted text to clipboard?

In my application I want the option to copy text as formatted string to clipboard, with parts in italic and other parts in bold, to be pasted later to MS Word or Google Doc. I have the following code:
QString str = "A text with <i>italic</i> and <b>bold</b> words."
QClipboard *clipboard = QApplication::clipboard();
QMimeData *rich_text = new QMimeData;
rich_text->setHtml(str);
clipboard->setMimeData(rich_text);
Everything works fine - when I later paste from clipboard to MS Word, I have formatted text. But if I paste to Google Doc, nothing happens (nothing is being pasted at all). Also, if I paste into simple text editor (say, Notepad), nothings is being pasted as well. I would expect in this case to be pasted only plain text without html tags - e.g., if I select and copy rich text in MS Word and paste into text editor, I get plain text, without any formatting information. How can I do that in Qt?

Newlines entered in Firefox not dislplaying in SQR Report

Let's say I have a text field here named "Description". In the Description field, I entered the following text:
This is line 1.
This is line 2.
This is line 3.
When I input these text to the Description field using IE or Chrome and run the SQR process, the description is displayed correctly including the newlines. But when I enter the same description using Firefox (v35.0.1 btw), the description is being printed in the report like this:
This is line 1. This is line 2. This is line 3.
I am sure that in my SQR there are no procedures that strip off the newlines (because it is working with IE and Chrome). I have also validated backend that the description has newlines.
Using the data entered in Firefox, I also tried running the report in IE and Chrome, but the newlines are still not displaying.
Can you tell me why is this happening? Is there a difference between the newlines used by IE, Chrome, and Firefox?
This is a known issue, google firefox textarea newline.
Firefox represents an newline as linefeed character ascii(10) whereas internet explorer as a combination of carriage return character and linefeed character ascii(13) ascii(10).
To ensure the data is saved in the way it's required for your further processes, you could add component record peoplecode, SavePreChange:
/* Newline is Char13)+Char(10) */
YOUR_REC.YOUR_FLD.Value = Substitute(
Substitute(YOUR_REC.YOUR_FLD.Value,
Char(13) | Char(10),
Char(10)),
Char(10),
Char(13) | Char(10));

qt qstring toStdString loss of minus sign

I am using a qstring and using the function toStdString(). When I do this I lose a minus sign:
'332-_09I_W'
this text becomes:
'332_09I_W'
What can I do to prevent this?
EDIT: Actually, the problem is not when i use toStdString(), it is when I set the text in my qTextEdit. The change occurs here:
myTextEdit->setHtml(myString);
I've tried:
QString qs("332-_091_W");
std::string st = qs.toStdString();
ui->textEdit->setHtml(st.c_str());
It gives no problem to me. Which version of Qt are you using?
However, from the documentation:
setHtml() changes the text of the text edit. Any previous text is removed
and the undo/redo history is cleared. The input text is
interpreted as rich text in html format.
Note: It is the responsibility of the caller to make sure that the text is correctly decoded when a QString containing HTML is created
and passed to setHtml().
The minus/hyphen symbol is ambiguous in HTML, try to change it in the QString (before passing it to setHtml()) with −

Does QString::fromUtf8 automatically reverse a Hebrew string?

I am having a problem where a Hebrew string is being displayed in reverse. I use QTableWidget to display some info, and here the string appears correctly using:
CString hebrewStr; hebrewStr.ToUTF8();
QString s = QString::fromUtf8( hebrewStr );
In another part of my program this same string is displayed on the screen, but not using QT, and this is what is being shown in reverse:
CString hebrewStr;
hebrewStr.ToUTF8();
I have debugged and hebrewStr.ToUTF8() in both cases produces the exact same unicode string, but the string is only displayed correctly in the QTableWidget. So I am wondering if Qt automatically reverses a given Hebrew string (since it is a rigth-to-left language). Thanks!
Yes, in this case QString generate the full unicode wchar_t from the UTF-8 encoded string. If you would like to do similar thing in MFC, you should use CStringW and decode the string.
Use MultiByteToWideChar for UTF8 to CStringW conversion.
Connected question in StackOverflow.

Resources