Results 1 to 6 of 6

Thread: How to create a caret in a widget which has no inputbox?

  1. #1
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How to create a caret in a widget which has no inputbox?

    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.

  2. #2
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: How to create a caret in a widget which has no inputbox?

    Maybe it's better to use standard QLineEdit/QTextEdit and style it to whatever your want?
    Oleg Shparber

  3. #3
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create a caret in a widget which has no inputbox?

    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.

  4. #4
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: How to create a caret in a widget which has no inputbox?

    Maybe I misuderstood your question, but Qt can handle Asian characters without problems, so you can simply work with QString.
    Oleg Shparber

  5. #5
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to create a caret in a widget which has no inputbox?

    Quote Originally Posted by Michael_BJFU View Post
    QMyCaret subcalssed from QObject
    are you sure? I hope you made a typo here and you meant QWidget instead of QObject.

  6. #6
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create a caret in a widget which has no inputbox?

    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.
    screenshot.jpg


    Added after 17 minutes:


    Quote Originally Posted by nish View Post
    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.
    Last edited by Michael_BJFU; 15th November 2011 at 13:23.

Similar Threads

  1. Create ui from widget
    By Fastman in forum Qt Programming
    Replies: 2
    Last Post: 29th November 2010, 19:53
  2. How to Create child widget behind parent widget?
    By anupamgee in forum Qt Programming
    Replies: 6
    Last Post: 22nd June 2010, 13:03
  3. How to create my own widget
    By jayreddy in forum Qt Programming
    Replies: 4
    Last Post: 30th October 2009, 11:45
  4. how to create something like widget box in qt designer
    By gregsan in forum Qt Programming
    Replies: 3
    Last Post: 18th July 2008, 15:21
  5. QFormbuilder - How to create widget
    By manivannan_1984 in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2006, 18:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.