Results 1 to 4 of 4

Thread: fetching each char entered in Qtextedit??

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Smile Re: fetching each char entered in Qtextedit??

    Hi Shuchi,

    Do the following:


    Qt Code:
    1. in header file
    2. protected:
    3. bool eventFilter(QObject *target, QEvent *event);
    4. private:
    5. QTextEdit * m_pTxBox;
    6.  
    7. in cpp file:
    8. in constructor:
    9. m_pTxBox->installEventFilter(this);
    10.  
    11.  
    12. bool myWindow::eventFilter(QObject *target, QEvent *event)
    13. {
    14. if (target == m_pTxBox)
    15. {
    16. if (event->type() == QEvent::KeyPress)
    17. {
    18. QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
    19. std::string str = keyEvent->text().toStdString();
    20. char ch = str[0];
    21. emit keyPressed(ch); // emit signal keyPressed with char entered
    22. }
    23. }
    24. return QWidget::eventFilter(target, event);
    25. }
    To copy to clipboard, switch view to plain text mode 

    or you can make your own class like:

    Qt Code:
    1. class TextEdit : public QTextEdit
    2. {
    3. protected:
    4. void keyPressEvent(QKeyEvent *event);
    5. signals:
    6. void keyPressed(int);
    7. ...
    8. }
    9.  
    10. void TextEdit::keyPressEvent(QKeyEvent *event)
    11. {
    12. std::string str = event->text().toStdString();
    13. int ch = str[0];
    14. emit keyPressed(ch);
    15.  
    16. QTextEdit::keyPressEvent(event);
    17. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 16th February 2007 at 11:16. Reason: changed [html] to [code]

  2. The following user says thank you to rajesh for this useful post:

    Shuchi Agrawal (16th February 2007)

Similar Threads

  1. unable to save QCStrings properly in a buffer
    By nass in forum Qt Programming
    Replies: 13
    Last Post: 15th November 2006, 20:49
  2. Current char in QTextEdit
    By jlbrd in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 09:30
  3. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03

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.