Results 1 to 20 of 21

Thread: Qt 4.2 Shortcut Management

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Qt 4.2 Shortcut Management

    Is there a good tutorial on how to create a simple shortcut manager in Qt 4.2?

    I found this one on google, but it's using a lot of deprecated functions, and I don't know enough yet to update all of it: http://doc.trolltech.com/qq/qq14-actioneditor.html

    Thanks for the help,
    dave

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    I've written such a component myself for use with my IDE project. As soon as I'll have enough time I'll release a proper package but in the meantime you can get the sources (licensed under GPL) from Edyuk's SVN trunk or source packages

    It includes a translation-aware shortcut manager class (QShortcutManager) which can register one or more actions under a given context and assign them a shorcut (either the default one or another set by the user) and a configuration dialog, QShortcutDialog which shows a tree of registered shortcuts and allow the user to set shortcuts through a custom input dialog (double click on tree item, type your shortcut, click on the OK button and you're done!).
    The shortcuts are stored in XML files in a predefined location (you may need to change the source code to fit your needs in this domain...)

    Hope this helps you.
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    wow this sounds like exactly what i've been looking for. I will check it out and let you know how it goes. Thanks so much for the quick reply,

    Dave

  4. #4
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    I downloaded edjuk from sourceforge the other day but I don't see those files anywhere in there. Have they been renamed or moved?

    it looks like they are supposed to be in trunk/src/lib/qcumber but I don't see them there in the local copy i have.

  5. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    Quote Originally Posted by dvmorris View Post
    I downloaded edyuk from sourceforge the other day but I don't see those files anywhere in there. Have they been renamed or moved?

    it looks like they are supposed to be in trunk/src/lib/qcumber but I don't see them there in the local copy i have.
    Are you sure you get the right version??? If you used SVN the files must be here (unless the checkout failed someway), if you downloaded packages they must be these of version 0.8.0-rc1.

    the path to these files is : $PATH_TO_EDYUK/src/lib/qcumber where PATH_TO_EDYUK corresponds to the place where you extracted the archive or did your SVN checkout...
    the files you're interested in are : qshortcutmanager.h qshortcutmanager.cpp qshortcutdialog.h qshortcutdialog.cpp

    Alternatively, you can always use the SVN browse option on Sourceforge, access these files and copy there content by hand.
    Current Qt projects : QCodeEdit, RotiDeCode

  6. #6
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    is there an example in the svn checkout that uses the shortcut manager? like a hello world kind of example or something?

  7. #7
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    Quote Originally Posted by dvmorris View Post
    is there an example in the svn checkout that uses the shortcut manager? like a hello world kind of example or something?
    Well I'm afraid I did not make any example... However it is really simple to use and here is a sample code :

    Qt Code:
    1. #include "qshortcutmanager.h"
    2.  
    3. #include <QMenu>
    4. #include <QAction>
    5. #include <QMenuBar>
    6. #include <QMainWindow>
    7. #include <QMessageBox>
    8. #include <QApplication>
    9.  
    10. int main(int argc, char **argv)
    11. {
    12. QApplication app(argc, argv);
    13.  
    14. QShortcutManager sm;
    15.  
    16. QMessageBox ms(&main);
    17. ms.setText( "This is a stub message box. The\n"
    18. "only nice thing about it is that\n"
    19. "it is triggered via a configurable\n"
    20. "shortcut\n\n"
    21. "So long buddy!");
    22.  
    23. QMenu help("&Help", &main);
    24.  
    25. QAction *a = new QAction("Show message box", &main);
    26. ms.connect( a , SIGNAL( triggered() ),
    27. SLOT ( exec() ) );
    28.  
    29. sm.registerAction(a, "Help", "CTRL+M");
    30. help.addAction(a);
    31.  
    32. QMenu settings("&Settings", &main);
    33.  
    34. QAction *b = new QAction("Configure &shortcuts", &main);
    35. sm.connect( b , SIGNAL( triggered() ),
    36. SLOT ( configure() ) );
    37.  
    38. sm.registerAction(b, "Settings", "CTRL+S");
    39. settings.addAction(b);
    40.  
    41. main.menuBar()->addMenu(&settings);
    42. main.menuBar()->addMenu(&help);
    43. main.show();
    44.  
    45. return app.exec();
    46. }
    To copy to clipboard, switch view to plain text mode 

    Of course to compile this you need to link against Edyuk core library or to pack the need components in your project (no path relocation in the example below : it is assumed that you copied the files in your project folder...) :

    Qt Code:
    1. QT *= xml
    2.  
    3. HEADERS += qshortcutmanager.h qshortcutdialog.h
    4. SOURCES += qshortcutmanager.cpp qshortcutdialog.cpp
    5.  
    6. FORMS += shortcutdialog.ui
    To copy to clipboard, switch view to plain text mode 

    Hope this helps.

    P.S : I just checked Edyuk sources and the settings storage path is incorrectly set. If you wish to use QShortcutManager within one of your application you should change some code in qshortcutmanager.cpp Replace the content of the QShortcutManager::file(const QString& lang) function with the code below :
    Qt Code:
    1. QString QShortcutManager::file(const QString& lang)
    2. {
    3. return QDir::homePath()
    4. + QDir::separator()
    5. + "."
    6. + QApplication::applicationName()
    7. + QDir::separator()
    8. + "shortcuts_"
    9. + lang
    10. + ".xml";
    11. }
    To copy to clipboard, switch view to plain text mode 
    Current Qt projects : QCodeEdit, RotiDeCode

  8. #8
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    Wow this example is really great. I think I have most of it integrated into my code properly but I am getting an error:

    Qt Code:
    1. qshortcutmanager.cc: In member function 'void QShortcutManager::destroyed(QObject*)':
    2. qshortcutmanager.cc:396: error: 'quintptr' was not declared in this scope
    To copy to clipboard, switch view to plain text mode 

    I have put qcumber.h into my directory, and the four files for the qshortcut stuff, but I don't really see any other files I'm supposed to include.

  9. #9
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    Quote Originally Posted by dvmorris View Post
    Wow this example is really great. I think I have most of it integrated into my code properly but I am getting an error:

    Qt Code:
    1. qshortcutmanager.cc: In member function 'void QShortcutManager::destroyed(QObject*)':
    2. qshortcutmanager.cc:396: error: 'quintptr' was not declared in this scope
    To copy to clipboard, switch view to plain text mode 
    I have put qcumber.h into my directory, and the four files for the qshortcut stuff, but I don't really see any other files I'm supposed to include.
    This is weird... quintptr is a very convinient typedef defined in qglobal.h
    I have no idea why it wouldn't compile properly on your box but you can always replace any occurence with : (void*)
    Last edited by fullmetalcoder; 28th February 2007 at 18:35. Reason: typo
    Current Qt projects : QCodeEdit, RotiDeCode

  10. #10
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    I just tried adding

    #include <QtGlobal>

    to my qshortcutmanager.cpp file, but it didn't seem to work. It looks like quintptr is declared in QtGlobal, but that change gives the same error.

    http://stuff.mit.edu/afs/athena/soft.../qtglobal.html

  11. #11
    Join Date
    Feb 2007
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    you know what? It may be a problem that I am actually using Qt 4.1 and not Qt 4.2.

    Qt 4.2 will not install on my mac for some reason, it gets two errors right at the end:

    http://www.qtcentre.org/forum/f-inst...os-x-5867.html

  12. #12
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    Quote Originally Posted by dvmorris View Post
    you know what? It may be a problem that I am actually using Qt 4.1 and not Qt 4.2.
    That's absolutely right and I hadn't spotted it... I'll place some macro'ed typedef to avoid troubles.
    Current Qt projects : QCodeEdit, RotiDeCode

  13. #13
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.2 Shortcut Management

    Quote Originally Posted by dvmorris View Post
    I just tried adding

    #include <QtGlobal>

    to my qshortcutmanager.cpp file, but it didn't seem to work. It looks like quintptr is declared in QtGlobal, but that change gives the same error.

    http://stuff.mit.edu/afs/athena/soft.../qtglobal.html
    it is documented here : http://stuff.mit.edu/afs/athena/soft...intptr-typedef

    and should be defined in any context provided that you have ANY Qt header included in the source. This is the case in qshortcutmanager.cpp so my only suggestion is to try #include "qglogal.h" and if it still doesn't work replace the occurence or add the typedef by hand in the source file :
    Qt Code:
    1. typedef void* quintptr;
    To copy to clipboard, switch view to plain text mode 
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. Replies: 1
    Last Post: 9th February 2007, 10:41
  2. shortcut with more than one key
    By ChasW in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2007, 07:38
  3. Trying to set shortcut
    By mikro in forum Newbie
    Replies: 2
    Last Post: 30th November 2006, 10:55
  4. Memory management in QT
    By Gayathri in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2006, 08:21
  5. Multi frame management ... is it possible ?
    By yellowmat in forum Newbie
    Replies: 8
    Last Post: 25th January 2006, 11:41

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.