Results 1 to 15 of 15

Thread: Using Short cut keys

  1. #1
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Using Short cut keys

    I use Open Suse10.2.

    I have an "Undo" menu which has a ctr+z short key.

    When there are no more items to delete from my MainWindow widget,then i disable the menu and associated action (undoId->setEnabled(false)

    But the short cut key(ctr+Z) is still enabled.

    Here is the snapshot of my program.

    Qt Code:
    1. Chemedit::Chemedit(QWidget *parent):QMainWindow( parent )
    2. {
    3. _undoIcon = new QIcon("/home/rajeev/niveditha/trialofevent/src/Undo.png" );
    4. menubar=QMainWindow::menuBar ();
    5. edit = new QMenu();
    6.  
    7. edit = menuBar()->addMenu(tr("&Feby _ Menu"));
    8.  
    9. undoId = edit->addAction("Action_undo ]", this , SLOT(undo()),QKeySequence::Undo);
    10. edit->addAction("Enable_Undo",this,SLOT(enableUndo()) );
    11. undoId->setToolTip( tr("Undo last drawing") );
    12. undoId->setStatusTip(tr("Undo last drawing"));
    13. undoId->setEnabled(true);
    14.  
    15. }
    16. void Chemedit::disableundo()
    17. {
    18. QMessageBox::information( this ," In Chemedit",
    19. "To inform you that we are DISABLING the Chemedit::undo()" );
    20. undoId->setEnabled(false);
    21. }
    To copy to clipboard, switch view to plain text mode 


    Thank You.
    Last edited by jpn; 12th March 2008 at 13:36. Reason: missing [code] tags

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

    Default Re: Using Short cut keys

    Do you use the Qt undo/redo framework? If so, it should update the action automatically.

  3. #3
    Join Date
    Feb 2008
    Posts
    19
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Using Short cut keys

    No we do not use the QT Undo/Redo framework.

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

    Default Re: Using Short cut keys

    Which version of Qt are you using?

  5. #5
    Join Date
    Feb 2008
    Posts
    19
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Using Short cut keys

    We are using Qt 4.2.2.

  6. #6
    Join Date
    Jan 2006
    Location
    Boston, MA
    Posts
    40
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Using Short cut keys

    Try to disable action, but not only menu.

  7. #7
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Using Short cut keys

    Quote Originally Posted by wysota View Post
    Do you use the Qt undo/redo framework? If so, it should update the action automatically.
    Please see the below code, forget about whatever i have explained in previous threads..

    Problem what i am facing is ...
    =>i am using Qt::Ctrl + Qt::key_z for UNDOing.
    => I am passing these QKeysequence in the function
    Qt Code:
    1. addAction( ..., ..., ..., Qt::Ctrl + Qt::key_z )
    To copy to clipboard, switch view to plain text mode 
    => In some cases i am disabling the action(QAction). so the key sequence also suppose to be disabled.
    => In windows keysequence is DISABLING along with the action DISABLING , but in Linux the keysequence is ACTIVE even after the action( QAction) is disabled..
    WHY ....????

    Here is the small code snippt.
    Attached Files Attached Files

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

    Default Re: Using Short cut keys

    Try this and see if it works:
    Qt Code:
    1. undoId = new QAction(this);
    2. undoId->setText("Action_undo");
    3. undoId->setShortcut(QKeySequence("CTRL+Z"));
    4. edit->addAction(undoId);
    5. connect(undoId, SIGNAL(triggered()), this, SLOT(undo()));
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Using Short cut keys

    Quote Originally Posted by wysota View Post
    Try this and see if it works:
    Qt Code:
    1. undoId = new QAction(this);
    2. undoId->setText("Action_undo");
    3. undoId->setShortcut(QKeySequence("CTRL+Z"));
    4. edit->addAction(undoId);
    5. connect(undoId, SIGNAL(triggered()), this, SLOT(undo()));
    To copy to clipboard, switch view to plain text mode 
    Wysota,
    Even you solution is not working .
    My question is why it's working ( as per expectation or document ) in Windows and not working in Linux ...?


    Is it a bug of qt4.x

    thanks in advance

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

    Default Re: Using Short cut keys

    No, I doubt that. I'd rather suspect you create the action two times or something like that. I'm not convinced there is even a QShortcut object created when assigning the shortcut.

  11. #11
    Join Date
    Feb 2008
    Posts
    19
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Using Short cut keys

    Quote Originally Posted by wysota View Post
    No, I doubt that. I'd rather suspect you create the action two times or something like that. I'm not convinced there is even a QShortcut object created when assigning the shortcut.


    See the below code and please tell me where is the fault..

    Qt Code:
    1. ***************************************************************************/
    2.  
    3.  
    4. #ifdef HAVE_CONFIG_H
    5. #include <config.h>
    6. #endif
    7.  
    8. #include <stdio.h>
    9. #include <stdlib.h>
    10. #include <Qt>
    11. #include <QMainWindow>
    12. #include <QMenu>
    13. #include <QMenuBar>
    14. #include <QAction>
    15. #include <QKeySequence>
    16. #include <QString>
    17. #include<QShortcut>
    18.  
    19. #include <QMessageBox>
    20. #include <QApplication>
    21.  
    22. #include "MyMainWindow.h"
    23.  
    24.  
    25.  
    26. Chemedit::Chemedit(QWidget *parent):QMainWindow( parent )
    27. {
    28. menubar=QMainWindow::menuBar ();
    29. edit = new QMenu();
    30. Q_CHECK_PTR( edit );
    31. edit = menuBar()->addMenu(tr("&Feby _ Menu"));
    32.  
    33. undoId = edit->addAction("Action_undo ]", this , SLOT(undo()),Qt::CTRL+Qt::Key_Z);
    34. disableUndo = edit->addAction("Disable_Undo",this,SLOT(disableundo()));
    35. EnableUndo = edit->addAction("Enable_Undo",this,SLOT(enableUndo()) );
    36. undoId->setEnabled(true);
    37.  
    38. }
    39. void Chemedit::disableundo()
    40. {
    41. QMessageBox::information( this ," In Chemedit",
    42. "To inform you that we are DISABLING the Chemedit::undo()" );
    43. undoId->setEnabled(false);
    44. }
    45. void Chemedit::enableUndo()
    46. {
    47. QMessageBox::information( this ," In Chemedit",
    48. "To inform you that we are ENABLING the Chemedit::undo()" );
    49. undoId->setEnabled(true);
    50. }
    51. void Chemedit::undo()
    52. {
    53. QMessageBox::information( this ," In Chemedit", "Chemedit::undo()" );
    54. }
    55. int main(int argc, char *argv[])
    56. {
    57. QApplication app(argc, argv);
    58. Chemedit mainWin;
    59. mainWin.show();
    60. return app.exec();
    61.  
    62. }
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Using Short cut keys

    IIRC this is a qt bug. Have you tried your program with qt 4.3 + ?
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

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

    Default Re: Using Short cut keys

    Works fine for me in Qt 4.3 and 4.4.

  14. #14
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Using Short cut keys

    Quote Originally Posted by wysota View Post
    Works fine for me in Qt 4.3 and 4.4.
    That means it is indeed qt 4.2.* bug. Unfortunately i couldn't find a related entry in task tracker.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

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

    Default Re: Using Short cut keys

    Quote Originally Posted by Gopala Krishna View Post
    That means it is indeed qt 4.2.* bug.
    I'm not so sure. Can someone test it against 4.2?

Similar Threads

  1. how to stop particular key's action in QLineEdit
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2008, 19:36
  2. Nullable foreign keys in QTableView
    By Banjo in forum Newbie
    Replies: 3
    Last Post: 31st January 2008, 22:07
  3. failing to achieve desired size of a BitField structure
    By nass in forum General Programming
    Replies: 8
    Last Post: 13th February 2007, 13:29
  4. Handling of dead keys in keyPressEvent()
    By ghorwin in forum Qt Programming
    Replies: 4
    Last Post: 2nd December 2006, 12:26
  5. How can I associate arrow keys?
    By Mariane in forum Newbie
    Replies: 2
    Last Post: 20th January 2006, 18:31

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.