PDA

View Full Version : How to create a caret in a widget which has no inputbox?



Michael_BJFU
15th November 2011, 10:07
I want to crearte a caret in a specific widget which has no inputbox? Could you help me?
At present, I created a class called QMyCaret subcalssed from QObject, drawed a line and then use a timer to control it to show or hide.
But I think it can't be the right solution, because there's a function called "CreateCaret" in the Win32 API.

Oleg
15th November 2011, 10:27
Maybe it's better to use standard QLineEdit/QTextEdit and style it to whatever your want?

Michael_BJFU
15th November 2011, 10:51
Thanks for your reply. You mean there's no convenient way to solve the problem? eh, OK. I think I should make the background transparent.
In addition, if I want to get the Asian Charactor using a local input software, what should I do? In the function "keyPressEvent" and get it by the event->key()? But it doesn't work so well.

Oleg
15th November 2011, 10:57
Maybe I misuderstood your question, but Qt can handle Asian characters without problems, so you can simply work with QString.

nish
15th November 2011, 11:05
QMyCaret subcalssed from QObject
are you sure? I hope you made a typo here and you meant QWidget instead of QObject.

Michael_BJFU
15th November 2011, 13:23
I think I should make the question clear.
Now,in the keyPressEvent( QKeyEvent * event ), I can get only one value of specific key by event->key() such as 'a' or 'b';
But from the picture, we can see before we press down the specific number on keyborad('秒' is 1), the keyPressEvent() function will not be called.
Then, after I kick the number, I can't catch the event either.
7099

Added after 17 minutes:


are you sure? I hope you made a typo here and you meant QWidget instead of QObject.
Yes, you are right. Thanks for your attention.