I've encountered some feature in Qt widgets QTextEdit, QPlainTextEdit, etc that I wouldn't like to encounter. And I actually have no idea how to change this issue.
I want to cipher some text, replacing one unicode character with another unicode character, even if it is control one.
So I delcare a simple string this way:
QChar ch = (QChar)0x20;
QChar ch2 = (QChar)0xA0;
QString str; str.append(ch); str.append(ch2);
These are usual space (0x20) and some unusual No-Break Space (0xA0). In memory the string is absolutely perfect. But if I set it as a text of QTextEdit with ui->txt_ciphered->setPlainText(str); this No-Break Space (0xA0) becomes usual space. I guess that's because they are for some similar purposes, but I still want to get No-Break Space character in TextEdit so that I could copy it etc. like I can in Notepad++ in example.
How could I change this?
QTextEdit does not accept non-break space, why? How can I
still use non-break space with Qt edit controls?
The problem is that QTextEdit::plainText property expressively prevents non-break space from being inserted and converts it to just space character.
plainText : QString
This property gets and sets the text editor's contents as plain text.
Previous contents are removed and undo/redo history is reset when the
property is set.
If the text edit has another content type, it will not be replaced by
plain text if you call toPlainText(). The only exception to this is
the non-break space, nbsp;, that will be converted into standard
space.
Suggestion: use QTextEdit::setText.
If it still does an unwanted conversion or does not treat that symbol right, you need to choose HTML form of test for QTextEdit::setText by inserting the text containing in an envelope of html tags or <html>My text</html>.
Related
Is there a way to show escaped characters like carriage return line feed "\r\n" characters in a QLineEdit in a human readable (escaped) way automatically?
Alternatively is there an easy method to automatically generate an escaped string.
Also I need to allow the user to edit the escaped string and when reading back the current text from the QLineEdit, storing it in a std::string it has to be non-escaped.
Use case.
I want the user to set a termination string (for example \r\n) for a communication object. Passing \r\n to a QLineEdit without any manual escaping, results in two unvisible characters in the QLineEdit input box.
"\\r\\n" ? You can create an inline stub the calls qstring::replace and return std with .toStdString
I'm a new user who using mainframe, I have a file and I need to change all dots '.' in file with space, I was trying to write this statement on command
change X'05' X'40' all
after I converted the file to hexdecimal, but It doesn't work.
How can I change all the dots with space in file, in simple way please?
The dots are non-displayable characters. You can match them using picture strings in the ISPF editor (which is what I assume you're trying to use to edit the file?)
Try the command
change p'.' ' ' all
The "p'.'" part will match any non-displayable character and change it to a blank.
Hans answer above will certainly change any non-displayable character to a space. However you need to make sure you really want to change all non displayable characters to a space. Turn HEX ON to look at the actual data. You can then do a F p'.' to find the non-displayable character(s) prior to changing it. Browse shows non-displayable characters as a dot. However Edit would replace the value with an attribute for display purposes and this keeps you from typing over the data. You have to turn on HEX mode to manually modify the non-displayable value or use the Change command as you were trying. Typically any hex value from x'00' - x'3F' would be non-displayable. So a
C P'.' X'40' ALL
would modify every one of those values to a space. This may or may not be desirable depending on the file.
So I've outputted a string of various ASCII characters. This program involves parts of this string being modified, and then re-displayed.
Instead of clearing the entire screen and re-displaying everything, which produces an unwanted flicker effect, I've decided on moving the cursor and then rewriting only the characters that have changed.
I'm moving the cursor with SetConsoleCursorPosition, part of windows.h.
However, once I try and cout something, it pushes all of the text in front of it ahead by a space; another unwanted effect.
In an attempt to fix this, I tried various forms of 'cout<<"\b";' to remove the old, unmodified character. But there was either no effect, or it actually added a space, which is obviously not a desired effect here.
I read somewhere that in order to remove the unwanted character that you actually have to use the escape sequence twice, Example: '\b\b', because the first one moves the cursor back a space, and the second one overwrites the character in front of it with a space (' ') or something like that.
'\b\b' didn't work either, unsurprisingly. Or maybe that is surprising, I don't actually know.
My question is: How do I remove the unwanted character? Or better yet, How do I overwrite text that has already been outputted with new text?
EDIT: I apologize, I'm running Windows 7
I think maybe clearing the ENABLE_INSERT_MODE with the SetConsoleMode function might help. It should prevent the console from inserting characters and pushing the old characters forward.
I'm extending a QPlainTextEdit.
When I double click on a word containing a pipe char ex : {"foo"|upper|reverse}
the whole text is surrounded.
I'd like to exclude the pipe char "|" from the selection and don't know what to do
Is there a way to change the behavior of QTextCursor::WordUnderCursor?
I'd like that char to act the same as a space or more generally as an unselectable char.
As stated in QT docs:
Selects the word under the cursor. If
the cursor is not positioned within a
string of selectable characters, no
text is selected.
Currently there is no official way to change the way a text edit finds the word boundaries. See http://bugreports.qt-project.org/browse/QTBUG-150.
You may use their private API to change the behaviour of QTextEngine::atWordSeparator. This way is not recommanded by Qt. The pipe is recognized as word separator in 4.6 but not in 4.5.1 or earlier. I would suggest to update your Qt version, if that is an option. Otherwise you may give your QTextEdit a new QTextLayout with a modified QTextEngine.
I'm rendering some HTML in a QT QLabel. The HTML looks like this:
<pre>foo\tbar</pre>
(note that I've put "\t" where there is a tab chracter in the code).
This renders fine, but the tab character appears to be rendered as eight spaces, whereas I want it to be redered as 4. How can I change this without having to change the source HTML?
According to W3 (HTML4):
The horizontal tab character (decimal 9 in [ISO10646] and [ISO88591]) is usually interpreted by visual user agents as the smallest non-zero number of spaces necessary to line characters up along tab stops that are every 8 characters. We strongly discourage using horizontal tabs in preformatted text since it is common practice, when editing, to set the tab-spacing to other values, leading to misaligned documents.
It's implementation-defined, essencially. Most, if not all, browsers/renderers use eight spaces for tabs. This cannot be configured in Qt.
It is, however somewhat trivial to go through your HTML and replace tabs with however many spaces you wish. Write a simple parser for that. Pseudocode:
for each <pre> block {
for each line in block {
position_in_line = 0
for each character in line {
if character is a tab {
remove tab character
do {
add a space character
++position_in_line
} while position_in_line % 8 != 0
} else {
++position_in_line
}
}
}
}
In case you're curious, HTML3 specifies the use of eight-character tabs:
Within <PRE>, the tab should be interpreted to shift the horizontal column position to the next position which is a multiple of 8 on the same line; that is, col := (col+8) mod 8.
While QLabel uses a QTextDocument internally when rendering rich text, it does not allow access to it in it's API. However, since QTextDocument is a QObject, you can try to use
QTextDocument * tl = label->findChild<QTextDocument>();
to get access to it (will work if the QLabel creates the QTextDocument as a (direct or indirect) child of itself).
Once you have a pointer to the text document, you can use the QTextDocument API, e.g. QTextOption::setTabsStop(), to change the tab stops.
The last step is to somehow make the QLabel repaint itself. Probably a call to QWidget::update() suffices, but caching (or worse, recreating the text document) might thward that. In this case, you can register an event listener on the label to adjust the text document just prior to a paintEvent(), but note that the sizeHint() might also change when the tab stops change, so it might be more complicated still.
That said, it's how I'd approach the problem.
Try this:
<pre style="tab-interval:0.5in">foo\tbar</pre>
Could work