I have a Qt main window with QCheckBox and QPushButton and a sub QGLwidget class widget for graphics rendering.
I have put into void Ui_MainWindow::setupUi(QMainWindow *MainWindow)
member function :
void Ui_MainWindow::setupUi(QMainWindow *MainWindow)
{
pushButton_2 = new QPushButton(widget);
...
checkBox_3 = new QCheckBox(widget);
...
widget_2 = new GLWidget(widget);
widget_2->setFocusPolicy(Qt::StrongFocus);
widget_2->setFocus();
...
}
I have created signals which modify the graphics rendering of widget_2
:
void Ui_MainWindow::createSignals()
{
...
connect(pushButton_2, SIGNAL(clicked()), this, SLOT(pauseSimu()));
connect(checkBox_3, SIGNAL(clicked()), this, SLOT(hideClassic()));
...
}
To always keep the focus on widget_2
despite clicking on pushButton_2
or checkBox_3
, I have to put into pauseSimu()
and hideClassic()
:
void Ui_MainWindow::pauseSimu()
{
widget_2->setFocus();
...
}
and
void Ui_MainWindow::hideClassic()
{
widget_2->setFocus();
...
}
The key events on widget_2 GLWidget
are coded in the GLWidget class member functions.
How could I avoid to use setFocus()
in all signals functions for always keeping the focus on widget_2
GLWidget ?
Try calling setFocusPolicy(Qt::NoFocus)
on your button and checkbox.