Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28

Thread: Catch a Key, like designer

  1. #21
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Catch a Key, like designer

    minimal compilable example which reproduce your problem.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  2. #22
    Join Date
    Jan 2007
    Posts
    201
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22

    Default Re: Catch a Key, like designer

    Qt Code:
    1. lineDeNo->installEventFilter(this);
    2. lineMa->installEventFilter(this);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. bool formAyarlar::eventFilter(QObject *o, QEvent *e)
    2. {
    3. if (o == lineDeNo && e->type() == QEvent::KeyPress) {
    4. const QKeyEvent *ke = static_cast<QKeyEvent *>(e);
    5. const QKeySequence ks(ke->modifiers() + ke->key());
    6. lineDeNo->setText(ks.toString(QKeySequence::NativeText));
    7. }else if (o == lineMa && e->type() == QEvent::KeyPress) {
    8. const QKeyEvent *ke = static_cast<QKeyEvent *>(e);
    9. const QKeySequence ks(ke->modifiers() + ke->key());
    10. // lineMa->setText(ks.toString());
    11. lineMa->setText(ks.toString(QKeySequence::PortableText));
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

  3. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Catch a Key, like designer

    This is not compilable A compilable example is something that includes a main() and the piece of code you want tested so that if one writes qmake && make it will compile.

    And please don't start multiple threads on the same subject. Moving to newbie (again).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #24
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Catch a Key, like designer

    this how should look like "minimal compilable example"
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class TestWidget: public QWidget
    4. {
    5. Q_OBJECT
    6.  
    7. public:
    8. TestWidget(QWidget *parent = 0)
    9. : QWidget(parent)
    10. {
    11. QVBoxLayout *vbl = new QVBoxLayout(this);
    12. m_lineEditNativeText = new QLineEdit();
    13. m_lineEditPortableText = new QLineEdit();
    14.  
    15. m_lineEditNativeText->installEventFilter(this);
    16. m_lineEditPortableText->installEventFilter(this);
    17.  
    18. vbl->addWidget(m_lineEditNativeText);
    19. vbl->addWidget(m_lineEditPortableText);
    20. }
    21.  
    22. protected:
    23. bool eventFilter(QObject *o, QEvent *e)
    24. {
    25. if (e->type() == QEvent::KeyPress) {
    26. const QKeyEvent *ke = static_cast<QKeyEvent *>(e);
    27. const QKeySequence ks(ke->modifiers() + ke->key());
    28. if (o == m_lineEditNativeText)
    29. m_lineEditNativeText->setText(ks.toString(QKeySequence::NativeText));
    30. else if (o == m_lineEditPortableText)
    31. m_lineEditPortableText->setText(ks.toString());
    32. }
    33. return QWidget::eventFilter(o, e);
    34. }
    35.  
    36. private:
    37. QLineEdit *m_lineEditNativeText;
    38. QLineEdit *m_lineEditPortableText;
    39. };
    40.  
    41. int main(int argc, char **argv)
    42. {
    43. QApplication app(argc, argv);
    44.  
    45. TestWidget tw;
    46. tw.show();
    47.  
    48. return app.exec();
    49. }
    50.  
    51. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    works fine, but symbol duplicated.
    Last edited by spirit; 7th May 2009 at 09:32. Reason: updated contents
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. The following user says thank you to spirit for this useful post:

    aekilic (7th May 2009)

  6. #25
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Catch a Key, like designer

    intresting thing, if modify my code in this way
    Qt Code:
    1. if (o == m_lineEditNativeText) {
    2. m_lineEditNativeText->setText(ks.toString(QKeySequence::NativeText));
    3. m_lineEditPortableText->setText(ks.toString());
    4. }// else if (o == m_lineEditPortableText)
    5. // m_lineEditPortableText->setText(ks.toString());
    To copy to clipboard, switch view to plain text mode 
    then a string in m_lineEditPortableText contains text without duplicating letter.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. The following user says thank you to spirit for this useful post:

    aekilic (7th May 2009)

  8. #26
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Catch a Key, like designer

    crap, it's my mistake, eventFilter should look like
    Qt Code:
    1. bool eventFilter(QObject *o, QEvent *e)
    2. {
    3. if (e->type() == QEvent::KeyPress) {
    4. const QKeyEvent *ke = static_cast<QKeyEvent *>(e);
    5. const QKeySequence ks(ke->modifiers() + ke->key());
    6. if (o == m_lineEditNativeText) {
    7. m_lineEditNativeText->setText(ks.toString(QKeySequence::NativeText));
    8. return true;
    9. } else if (o == m_lineEditPortableText) {
    10. m_lineEditPortableText->setText(ks.toString());
    11. return true;
    12. }
    13. }
    14. return QWidget::eventFilter(o, e);
    15. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. The following user says thank you to spirit for this useful post:

    aekilic (7th May 2009)

  10. #27
    Join Date
    Jan 2007
    Posts
    201
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22

    Default Re: Catch a Key, like designer

    Let me try

  11. #28
    Join Date
    Jan 2007
    Posts
    201
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22

    Default Re: Catch a Key, like designer

    yes works perfect thank you very much spirit you are my life saver!

Similar Threads

  1. designer not showing menu items ...
    By wagmare in forum Installation and Deployment
    Replies: 0
    Last Post: 24th February 2009, 10:26
  2. Threads in Designer plugins
    By hvengel in forum Qt Tools
    Replies: 2
    Last Post: 3rd January 2009, 19:19
  3. Replies: 13
    Last Post: 15th December 2006, 11:52
  4. Designer crashes when selecting some widgets
    By gwendal in forum Qt Tools
    Replies: 4
    Last Post: 21st July 2006, 13:18
  5. Adding slots in Designer
    By jamos in forum Qt Tools
    Replies: 5
    Last Post: 18th May 2006, 23:28

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.