My problem is to navigate the tab headers using keyboard for QTabWidget.
My whole code look like follows .
{
Public :
ABC();
}
void ABC::ABC()
{
.......
.......
m_pMasterTab->installEventFilter(this);//event filter
}
//Event filter
{
int cnt = m_pMasterTab->count();
if(event
->type
() == QEvent::KeyPress) {
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
);
}
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 );
}
To copy to clipboard, switch view to plain text mode
Bookmarks