Page 1 of 2 12 LastLast
Results 1 to 20 of 28

Thread: Catch a Key, like designer

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

    Default Catch a Key, like designer

    Dear All

    I started a thread yesterday, but I dont know why and how, it has been moved to newbei

    What I would like to do is, like in designer, I would like to create a line, and when a press a line it should write on the line what I have pressed.

    Is the a example code for this, or where could I find the codes for the designer.

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

    Default Re: Catch a Key, like designer

    Quote Originally Posted by aekilic View Post
    I started a thread yesterday, but I dont know why and how, it has been moved to newbei
    because it's newbie question, just install event filter to your line edit and process QKeyEvent.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Catch a Key, like designer

    can u give more information about ur need ..

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

    Default Re: Catch a Key, like designer

    What I need is

    I would like to know which key has been pressed for a qline

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

    Default Re: Catch a Key, like designer

    here is an example, is it hard to write it by youself?
    Qt Code:
    1. ...
    2. lineEdit = new QLineEdit();
    3. lineEdit->installEventFilter(this);
    4. ...
    5. bool MyWidget::eventFilter(QObject *o, QEvent *e)
    6. {
    7. if (o == lineEdit && e->type() == QEvent::KeyPress) {
    8. const QKeyEvent *ke = static_cast<QKeyEvent *>(e);
    9. const QKeySequence ks(ke->modifiers() + ke->key());
    10. lineEdit->setText(ks.toString());
    11. }
    12. return QWidget::eventFilter(o, e);
    13. }
    To copy to clipboard, switch view to plain text mode 
    nothing special, right?
    that's why you question is newbie.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Catch a Key, like designer

    use keypressEvent and check with the respected key ... QKeyEvent has a function
    bool operator== ( QKeyEvent * e, QKeySequence::StandardKey key ) where standard keys will help u ..

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

    Default Re: Catch a Key, like designer

    Dear spirit

    Thank you very much for your reply yes you right it was easy but the problem is, we wrote a program which is open source there is a company who is selling a similar program whoes owner is treatening us everyday that we made a program like this. So I am not really thinking 100% sorry

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

    Default Re: Catch a Key, like designer

    I got another problem for this, the code you have sent is working fine spirit for CTRL

    When I press shift + r , it writes to the line SHIFT+RR or for ALT it writes ALT+Rr

    Can any ona tell me the reason?

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

    Default Re: Catch a Key, like designer

    try this
    Qt Code:
    1. lineEdit->setText(ks.toString(QKeySequence::NativeText));
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: Catch a Key, like designer

    no I still get

    Shift+HH when I press shift+h

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

    Default Re: Catch a Key, like designer

    what system do you use?
    under Windows this code works fine.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  12. #12
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Catch a Key, like designer

    in linus also the same problem arise .. if i press key "a" it shows "Aa" ...

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

    Default Re: Catch a Key, like designer

    from Qt Assistant
    QKeySequence::NativeText 0 The key sequence as a platform specific string. This means that it will be shown translated and on the Mac it will resemble a key sequence from the menu bar. This enum is best used when you want to display the string to the user.
    QKeySequence::PortableText 1 The key sequence is given in a "portable" format, suitable for reading and writing to a file. In many cases, it will look similar to the native text on Windows and X11.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: Catch a Key, like designer

    I use vista Qt4.5.0

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

    Default Re: Catch a Key, like designer

    take a look implementation of QtKeySequenceEdit in QTDIR\tools\shared\qtpropertybrowser\qttreepropert ybrowser.cpp.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: Catch a Key, like designer

    I accidentaly use this code
    Qt Code:
    1. if (o == lineDeNo && e->type() == QEvent::KeyPress) {
    2. const QKeyEvent *ke = static_cast<QKeyEvent *>(e);
    3. const QKeySequence ks(ke->modifiers() + ke->key());
    4. lineDeNo->setText(ks.toString(QKeySequence::NativeText));
    5. }
    6. if (o == lineMa && e->type() == QEvent::KeyPress) {
    7. const QKeyEvent *ke = static_cast<QKeyEvent *>(e);
    8. const QKeySequence ks(ke->modifiers() + ke->key());
    9. lineMa->setText(ks.toString());
    10. lineDeNo->setText(ks.toString(QKeySequence::PortableText));
    11. }
    To copy to clipboard, switch view to plain text mode 
    When editting lineDoNo it doesnt work but When I edit lineMa, lineDeNo works fine,

    I try
    Qt Code:
    1. if (o == lineDeNo && e->type() == QEvent::KeyPress) {
    2. const QKeyEvent *ke = static_cast<QKeyEvent *>(e);
    3. const QKeySequence ks(ke->modifiers() + ke->key());
    4. lineDeNo->setText(ks.toString(QKeySequence::PortableText));
    5. }
    To copy to clipboard, switch view to plain text mode 
    but it doesnt work...

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

    Default Re: Catch a Key, like designer

    do you install event filters for both lineedits?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: Catch a Key, like designer

    yes, I do install for both lines

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

    Default Re: Catch a Key, like designer

    ok, can you attach compilable example which contains this bug?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: Catch a Key, like designer

    do you mean the code for this area?

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.