I think you need to handle event from QTabBar, so next example is how to do this
TabWidget
::TabWidget(QWidget *parent
){
tabBar()->installEventFilter(this);
}
TabWidget::~TabWidget()
{
}
{
if (event
->type
() == QEvent::KeyPress && o
== tabBar
()) { QKeyEvent *keyEvent
= static_cast<QKeyEvent
*>
(event
);
if (keyEvent->key() == Qt::Key_Right) {
if (currentIndex() != 2) {
setCurrentIndex(2);
QWidget *widget
= this
->widget
(currentIndex
());
if (widget)
widget->setFocus();
return true;
}
}
}
}
TabWidget::TabWidget(QWidget *parent)
: QTabWidget(parent)
{
tabBar()->installEventFilter(this);
}
TabWidget::~TabWidget()
{
}
bool TabWidget::eventFilter(QObject *o, QEvent *event)
{
if (event->type() == QEvent::KeyPress && o == tabBar()) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Right) {
if (currentIndex() != 2) {
setCurrentIndex(2);
QWidget *widget = this->widget(currentIndex());
if (widget)
widget->setFocus();
return true;
}
}
}
return QTabWidget::eventFilter(o, event);
}
To copy to clipboard, switch view to plain text mode
I hope it helps you.
Bookmarks