PDA

View Full Version : keyboard left and right arrows in qt 3.3.5



rajaraob
21st February 2007, 14:32
hi ,
i am using QTabWidget for my application . I want to use left and right arrows to navigate around tabs . I am using qt 3.3.4

please let me know which property on QTabWidget be given.

Thanks in advance for your help .

regards
raja rao

e8johan
21st February 2007, 19:18
You could install an event filter that catches the key presses for the keys that you are interested in. The you can move between the tabs programatically depending on the keys.

rajaraob
22nd February 2007, 08:06
Thanks for you response.
i have installed event filter for QTabWidget object .

I can able to catch all key board events except left and right arrows .

Left arrow, right arrow and other keys are working fine for QLineEdit installedEventFilters(..).

Is there any reason why QTabWidget installedEventFilters(...) are not capturing left and right arrow key board events or is it a bug ?

I am using qt 3.3.5 and windows xp OS .

And please do provide me url for known issues in 3.3.5 for installEventFilters(..) if any.

Regards
Raja Rao

jpn
22nd February 2007, 08:32
i have installed event filter .
I can able to catch all key board events except left and right arrows .
Could you show the code of eventFilter()?

rajaraob
22nd February 2007, 10:50
My problem is to navigate the tab headers using keyboard for QTabWidget.
My whole code look like follows .


class ABC :: QObject
{
Public :
ABC();
}

void ABC::ABC()
{
.......
.......
QTabWidget m_pMasterTab = new QTabWidget();
m_pMasterTab->installEventFilter(this);//event filter
}
//Event filter
bool ABC::eventFilter(QObject * target, QEvent * event)
{
int cnt = m_pMasterTab->count();

if(event->type() == QEvent::KeyPress)
{
QKeyEvent *k = (QKeyEvent*)event;
Qt::Key keyPressed = (Qt::Key)k->key();
if(keyPressed == Qt::Key_Left)
{
int indx = m_pMasterTab->currentPageIndex();
m_pMasterTab->setCurrentPage ((indx ==0)?cnt:indx-1 ) ;
}
if(keyPressed == Qt::Key_Right)
{
int indx = m_pMasterTab->currentPageIndex();
m_pMasterTab->setCurrentPage ((indx+1)%cnt ) ;
}

}
return QObject::eventFilter( object, event );
}

jpn
22nd February 2007, 12:03
Looks like a double thread (http://www.qtcentre.org/forum/f-qt-programming-2/t-eventqevent-event-5759.html) to me. And this is not related to Qt Designer either..