PDA

View Full Version : Font and lineedit



Raghaw
16th May 2012, 11:20
Hi ,

Is there any font which QlineEdit supports to display the non-Printable characters .

Lykurg
16th May 2012, 13:52
You can use any font installed at your operating system with QLineEdit you just have to set it with setFont(). Further you can use a non installed font by register it to the QApplication instance.

Raghaw
17th May 2012, 06:10
Actually the problem is that when i want to display a non-printable character its not being displayed in lineedit.Any idea what should i do to display it

Charvi
17th May 2012, 07:54
Well what does printing non-printable characters mean? Like how do you print BACKSPACE, EOT, ETX, STX, etc..
AFAIK thats not possible in Qt.

What is your use case? May be that may help to find a way out.

ChrisW67
17th May 2012, 08:58
Actually the problem is that when i want to display a non-printable character its not being displayed in lineedit.Any idea what should i do to display it

They are called non-printable for a reason. They have no glyph in the vast majority of fonts, and they have special meanings that may be used e.g. the bell or escape character. If you want non-printables to be displayed as some substitute character then substitute that character before display:


QString test = QString::fromUtf8(
"this string \v contains \ba\x01\x02 few odd characters\004"
"including a non-character \xEF\xB7\x90"
"and one defined as having no visible appearance >>\xE2\x80\x8C<<"
);

qDebug() << test;
for (int i = 0; i < test.size(); ++i)
if (!test.at(i).isPrint())
test[i] = QChar(QChar::ReplacementCharacter); // Unicode defines this character
qDebug () << test;

Raghaw
21st May 2012, 11:44
Thanks for replying...

Mine problem is that i have one lineedit which can be used to display hexadecimal and ANSI format of strings..I using a input mask in case of hexadecimal formatSo there is one comobox of Hexadecimal and ANSI option.if u choose Hexadecimal input mask will appear and is u choose ANSI option the Mask will dissapear and the corresponding values written in hexadecimal will be displayed in ANSI format and vice-verse.

Suppose u enter in HEX 0x23 it will display # in ANSI mode and vice versa.

Now here comes the problem ::
If u enter a value less than 0x20 it will a non printable character and hence a space will be created in place of that.So this will be confusion for user as he wont be to figurea space.So what i did i used a Text edit in place Lieneedit when u select a ANSI mode so that a square is generated when ever a non printable character is written.

But this creates many problem suppose if put "0x0D" in HEX and switch to ANSI and again switch to HEX it displays "0x0A" instead of 0x0D.

Is there any way i can show square in place of non printable character in lineedit also.

Please reply back.

Added after 5 minutes:

Thanks ChrisW67 .Is there any way also i can extract the characters which were replaced by replacement character.