PDA

View Full Version : Trying to set shortcut



mikro
29th November 2006, 22:42
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:

page1 = new QAction(this);
page1->setShortcut(QKeySequence(tr("Ctrl+F1")));
connect(page1, SIGNAL(triggered()), this, SLOT(openPage1()));
which i hope will call

void MainWindow::openPage1() {
tabWidget->setCurrentIndex(0);
}
(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?

sunil.thaha
30th November 2006, 08:53
Better would be something like this !!



QSignalMapper *signalMapper = new QSignalMapper(this);
for( int index=0; index < tabWidget->count(); ++index ){
QShortcut *shortcut =new QShortcut( QKeySequence(QString("Ctrl+F%1").arg( index +1 ) ), this );

connect( shortcut, SIGNAL(activated() ), signalMapper, SLOT( map() ) );
signalMapper->setMapping( shortcut, index );
}
connect( signalMapper, SIGNAL(mapped( int )),
tabWidget, SLOT(setCurrentIndex( int )) );

mikro
30th November 2006, 09:55
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 :))