PDA

View Full Version : Masking password in QTreeView



DmitryNik
22nd October 2011, 11:17
Hello!

I need to display bullets instead of actual password's signs in QTreeView's item. For this purpose I created own delegate: QLineEdit with echo mode 'Password'. Yes, for input it works perfectly. But here is a pitfall: setModelData -method. It will always display an actual data. My question is: Is any smart way to mask the password in QTreeView? Is it possible?

Thank you for your answers beforehand.

DmitryNik
23rd October 2011, 15:08
OK, I thought about that. And here is result: actual password will be copied into internal variable and instead of letters shall be put bullets "•"(alt + 0149).
For instance: "Hello!" - "••••••". So, it's just a decoration for an user.
I didn't see any smart ways to do that.

DmitryNik
23rd October 2011, 18:46
Here is another problem... Instead of bullets, QTreeView shows question-marks.
Here is the code:


item.setText(QString::fromUtf8("\x0095"));


Guys, do you have any ideas, how it can be fixed?

ChrisW67
23rd October 2011, 23:35
The character you are trying to get is 149 in the Windows CP 1252 code page. Its equivalent Unicode code point is U+2022 BULLET (http://www.unicode.org/charts/PDF/U2000.pdf). The UTF-8 encoding of U+2022 is three bytes E2 80 A2 (in hex, see http://people.w3.org/rishida/tools/conversion/ for useful tool).
So, you could use any of these:


QChar bullet(0x2022);
QString bullet = QString::fromStdWString(L"\x2022");
QString bullet = QString::fromUtf8("\xe2\x80\xa2");

depending on whether you want a single char or a string

DmitryNik
24th October 2011, 16:47
Thank you! It works.