#include "qapplication.h"
#include "qlabel.h"
#include "qtabwidget.h"
#include "qtabbar.h"
#include "qtextedit.h"
{
Q_OBJECT
public:
ABC
(QWidget * parent
= 0,
const char * name
= 0, WFlags f
= 0) {
tabBar()->installEventFilter(this);
}
{
if (watched == tabBar()) {
if(e
->type
() == QEvent::KeyPress) { Qt::Key keyPressed = (Qt::Key)k->key();
if (keyPressed == Qt::Key_Left) {
int indx = currentPageIndex();
setCurrentPage ((indx==0)?count()-1:indx-1 ) ;
return true;
} else if (keyPressed == Qt::Key_Right) {
int indx = currentPageIndex();
setCurrentPage ((indx+1)%count() );
return true;
}
}
}
}
protected:
};
int main(int argc, char* argv[])
{
ABC *abc = new ABC();
abc->addTab(label1, "Label1");
abc->addTab(label2, "Label2");
abc->addTab(edit1, "Edit1");
abc->show();
return app.exec();
}
#include "main.moc"
#include "qapplication.h"
#include "qlabel.h"
#include "qtabwidget.h"
#include "qtabbar.h"
#include "qtextedit.h"
class ABC : public QTabWidget
{
Q_OBJECT
public:
ABC(QWidget * parent = 0, const char * name = 0, WFlags f = 0)
: QTabWidget(parent, name, f)
{
tabBar()->installEventFilter(this);
}
virtual bool eventFilter(QObject *watched, QEvent *e)
{
if (watched == tabBar()) {
if(e->type() == QEvent::KeyPress) {
QKeyEvent *k = (QKeyEvent*)e;
Qt::Key keyPressed = (Qt::Key)k->key();
if (keyPressed == Qt::Key_Left) {
int indx = currentPageIndex();
setCurrentPage ((indx==0)?count()-1:indx-1 ) ;
return true;
} else if (keyPressed == Qt::Key_Right) {
int indx = currentPageIndex();
setCurrentPage ((indx+1)%count() );
return true;
}
}
}
return QTabWidget::eventFilter(watched, e);
}
protected:
};
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
ABC *abc = new ABC();
QLabel *label1 = new QLabel("Label1", abc);
abc->addTab(label1, "Label1");
QLabel *label2 = new QLabel("Label2", abc);
abc->addTab(label2, "Label2");
QTextEdit *edit1 = new QTextEdit(abc);
abc->addTab(edit1, "Edit1");
abc->show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks