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 Re: Qt 4.2 Shortcut Management

    How do I use the numbers as shortcuts? I can't seem to get them to work by themselves without adding a CTRL or ALT key before them.

    For example, I have a QTabWidget with five pages and I setup five modes like this

    Qt Code:
    1. modeBasicsAct = new QAction(QIcon(":/images/mode_basics.png"), tr("&Basics"), this);
    2. sm->registerAction(modeBasicsAct, "Modes", "1");
    3. modeBasicsAct->setStatusTip(tr("Switch to Basics Mode"));
    4. connect(modeBasicsAct, SIGNAL(triggered()), this, SLOT(switchMode(0)));
    To copy to clipboard, switch view to plain text mode 

    and I have a slot function defined like this:

    Qt Code:
    1. void MainWindow::switchMode(int pageId){
    2. modesTabWidget->setCurrentIndex(pageId);
    3. }
    To copy to clipboard, switch view to plain text mode 

    The 1,2,3,4,5 shortcuts I set with registerAction do not switch the TabWidget's currentIndex to 0,1,2,3,or 4, like I write in the slot function.

    Do you have any ideas as to why that won't work? I also noticed that it doesn't seem to work with any other shortcuts like CTRL+L. Maybe this has nothing to do with the numbers problem. anyways, sorry to bother you so much. I really appreciate your help. Your shortcut manager is phenomenal.

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

    Default Re: Qt 4.2 Shortcut Management

    Quote Originally Posted by dvmorris View Post
    How do I use the numbers as shortcuts? I can't seem to get them to work by themselves without adding a CTRL or ALT key before them.

    For example, I have a QTabWidget with five pages and I setup five modes like this

    Qt Code:
    1. modeBasicsAct = new QAction(QIcon(":/images/mode_basics.png"), tr("&Basics"), this);
    2. sm->registerAction(modeBasicsAct, "Modes", "1");
    3. modeBasicsAct->setStatusTip(tr("Switch to Basics Mode"));
    4. connect(modeBasicsAct, SIGNAL(triggered()), this, SLOT(switchMode(0)));
    To copy to clipboard, switch view to plain text mode 
    and I have a slot function defined like this:

    Qt Code:
    1. void MainWindow::switchMode(int pageId){
    2. modesTabWidget->setCurrentIndex(pageId);
    3. }
    To copy to clipboard, switch view to plain text mode 
    The 1,2,3,4,5 shortcuts I set with registerAction do not switch the TabWidget's currentIndex to 0,1,2,3,or 4, like I write in the slot function.

    Do you have any ideas as to why that won't work? I also noticed that it doesn't seem to work with any other shortcuts like CTRL+L. Maybe this has nothing to do with the numbers problem. anyways, sorry to bother you so much. I really appreciate your help. Your shortcut manager is phenomenal.
    The shortcut management provided is just a (very ) convinient wrapper over Qt shortcut mechanism but it doesn't modify it... AFAIK shortcuts NEED modifiers to work because other keys are generally forwarded to other widgets and this is especially true if you have, say, any kind of input widget in your current tab...

    Besides your slots registration is wrong : the SLOT() macro is passed a qualified function name ( name + parameters types) and no arguments... That's probably why your code is failing. If you use a special slot for each mode switching and make sure that the child widgets don't accept number keys input it should work...
    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

    ok I understand a little better now. I rewrote the slot functions so there is a unique one for each of the five TabWidget Pages. here is one of them:

    Qt Code:
    1. //inside MainWindow class in .h file
    2. private slots:
    3. void switchBasicsMode();
    4.  
    5. //in cpp file
    6. void MainWindow::switchBasicsMode(){
    7. modesTabWidget->setCurrentIndex(0);
    8. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. modeBasicsAct = new QAction(QIcon(":/images/mode_basics.png"), tr("&Basics"), this);
    2. sm->registerAction(modeBasicsAct, "Modes", "CTRL+9");
    3. modeBasicsAct->setStatusTip(tr("Switch to Basics Mode"));
    4. connect(modeBasicsAct, SIGNAL(triggered()), this, SLOT(switchBasicsMode()));
    To copy to clipboard, switch view to plain text mode 

    but that doesn't seem to work either. the signals slots demo here: http://doc.trolltech.com/4.2/signalsandslots.html is not very helpful either.

    The shortcut doesn't seem to do anything. But all the shortcuts for actions that are attached to menuBar items work fine (except single numbers and CTRL+Q). Do I just need to create a dummy menuBar for the five modes so that the shortcuts will do something?

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

    Default Re: Qt 4.2 Shortcut Management

    Quote Originally Posted by dvmorris View Post
    The shortcut doesn't seem to do anything. But all the shortcuts for actions that are attached to menuBar items work fine (except single numbers and CTRL+Q). Do I just need to create a dummy menuBar for the five modes so that the shortcuts will do something?
    I forgot to point this out as well... Qt, as far as I tested, forward shortcuts to VISIBLE actions only... If you don't attach your actions to menubars, toolbars, buttons or anything that can manage them, then the shortcut will never trigger the actions (except maybe if you play with the shortcut context but even that may fail...)
    Current Qt projects : QCodeEdit, RotiDeCode

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

    Default Re: Qt 4.2 Shortcut Management

    I'm attempting to compile this program on Windows, and it gives the following error:

    debug\moc_qshortcutdialog.cpp:40: error: definition of static data member 'QShortcutDialog::staticMetaObject' of dllimport'd class.
    debug\moc_qshortcutdialog.cpp:40: warning: 'QShortcutDialog::staticMetaObject' defined locally after being referenced with dllimport linkage
    mingw32-make[1]: *** [debug\moc_qshortcutdialog.o] Error 1
    mingw32-make[1]: Leaving directory `C:/Documents and Settings/dave/Desktop/thesis/topmod/trunk'
    mingw32-make: *** [debug] Error 2
    I found a post that you answered about a similar problem here:

    http://www.qtcentre.org/forum/f-qt-s...rary-3286.html

    but I'm not sure how to implement your fix in this case. Do you have any suggestions? Thanks for the help,
    dave
    Last edited by jacek; 5th March 2007 at 23:47. Reason: changed [code] to [quote]

Similar Threads

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