Results 1 to 2 of 2

Thread: KeyPressEvent hinders eidting the QTextEdit

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default KeyPressEvent hinders eidting the QTextEdit

    Dear Friend
    I have a QTextEdit I want to capture the KeyPressEvent and take each of the text user enters through keyboard. Late I want to change the color of those text. But when I reimplement KeyPressEvent() my text edit becomes choked means I am not able to edit anything. Why this is happening I want to be able to write text in the editor. Any suggestion would be highly appreciated. Thanks sujan

    Check the code snippet

    void CTextEditor::keyPressEvent ( QKeyEvent * e )
    {
    setFocusPolicy(Qt::NoFocus);
    QString text = e->text();
    tree->hlighter->highlightBlock(text);
    }

    void CTextEditor::keyPressEvent ( QKeyEvent * e )
    {
    setFocusPolicy(Qt::NoFocus);
    QString text = e->text();
    tree->hlighter->highlightBlock(text);
    }

    Just because I reimplemented KeyPressEvent I am not able to enter anything in the editor. Please give some suggestions.

  2. #2
    Join Date
    May 2011
    Posts
    239
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60
    Thanks
    4
    Thanked 35 Times in 35 Posts

    Default Re: KeyPressEvent hinders eidting the QTextEdit

    The first thing that comes to mind is setFocusPolicy(Qt::NoFocus), where you tell Qt that the control has no focus, so -- no editing. Otherwise, I'm not familiar with what keyPresseEvent should do.

Similar Threads

  1. CTRL-+ in keyPressEvent
    By The_Fallen in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2011, 23:40
  2. keypressevent
    By djwk in forum Newbie
    Replies: 9
    Last Post: 5th July 2010, 03:12
  3. Replies: 6
    Last Post: 17th March 2010, 11:53
  4. QTreeWidget keyPressEvent
    By hgedek in forum Qt Programming
    Replies: 3
    Last Post: 18th August 2007, 17:33
  5. Replies: 1
    Last Post: 16th February 2007, 08:22

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
  •  
Qt is a trademark of The Qt Company.