Results 1 to 3 of 3

Thread: Trying to set shortcut

  1. #1
    Join Date
    Apr 2006
    Location
    Erlangen, Germany
    Posts
    58
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Trying to set shortcut

    hi,
    i'd like to have shortcuts to change between the tabs of a tabwidget. after some searching through the fine manual and some posts i came up with:
    Qt Code:
    1. page1 = new QAction(this);
    2. page1->setShortcut(QKeySequence(tr("Ctrl+F1")));
    3. connect(page1, SIGNAL(triggered()), this, SLOT(openPage1()));
    To copy to clipboard, switch view to plain text mode 
    which i hope will call
    Qt Code:
    1. void MainWindow::openPage1() {
    2. tabWidget->setCurrentIndex(0);
    3. }
    To copy to clipboard, switch view to plain text mode 
    (and obviously two other, similar actions and functions for the other two tabs.

    nothing happens. i also tried to set the translation to Strg+F1 in linguist as i am using the app in german. Where am i going wrong?

  2. #2
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trying to set shortcut

    Better would be something like this !!

    Qt Code:
    1. QSignalMapper *signalMapper = new QSignalMapper(this);
    2. for( int index=0; index < tabWidget->count(); ++index ){
    3. QShortcut *shortcut =new QShortcut( QKeySequence(QString("Ctrl+F%1").arg( index +1 ) ), this );
    4.  
    5. connect( shortcut, SIGNAL(activated() ), signalMapper, SLOT( map() ) );
    6. signalMapper->setMapping( shortcut, index );
    7. }
    8. connect( signalMapper, SIGNAL(mapped( int )),
    9. tabWidget, SLOT(setCurrentIndex( int )) );
    To copy to clipboard, switch view to plain text mode 
    We can't solve problems by using the same kind of thinking we used when we created them

  3. The following user says thank you to sunil.thaha for this useful post:

    mikro (30th November 2006)

  4. #3
    Join Date
    Apr 2006
    Location
    Erlangen, Germany
    Posts
    58
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trying to set shortcut

    thank you, that was what it needed. Hadn't seen that there is a QShortcut as well.
    now i can dub my app 1.0 PRE 1 )

Similar Threads

  1. QIde, a new IDE for Qt4
    By jlbrd in forum Qt-based Software
    Replies: 114
    Last Post: 4th October 2006, 21:12

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.