[SOLVED] Set the focus on the viewport of the QDeclarativeView
-
Hi,
I have a QGlWidget and I have set it as the viewport of the
QDeclarativeView.
https://projects.kde.org/projects/playground/games/gluon/repository/revisions/master/entry/player/touch/main.cpp#L61
The widget is basically a QGLWidget inheritance, subclass.
https://projects.kde.org/projects/playground/games/gluon/repository/revisions/master/entry/graphics/renderwidget.h#L38
The QGLWidget gets the QDeclarativeView as the parent during the
object construction. (this is how I handle in my local clone)I have tried to call the d->widget->setFocus() here:
https://projects.kde.org/projects/playground/games/gluon/repository/revisions/master/entry/player/touch/gamewindowmanager.cpp#L83I have also tried to call the view->setFocus() here
https://projects.kde.org/projects/playground/games/gluon/repository/revisions/master/entry/player/touch/main.cpp#L62I also use event filtering, but that should hopfully not cause any issue:
https://projects.kde.org/projects/playground/games/gluon/repository/revisions/master/entry/player/touch/gamewindowmanager.cpp#L137Everything works just fine apart from the focus setting meaning that I
cannot handle any input events, keystrokes on that widget. I have
other standalone applications resembling the functionality and the
focus works just fine there for the QGLWidget.
https://projects.kde.org/projects/playground/games/gluon/repository/revisions/master/entry/player/qt/mainwindow.cpp#L118
125th: setCentralWidget( d->widget ); and 149th:
d->widget->setFocus() lines. In the latter case, I did not use any
QDeclarativeView, but QMainWindow.The viewport doesn't receive any events, basically. This is basic functionality of QAbstractScrollArea. It installs an event filter, turning all events into QAbstractScrollArea::viewportEvent. Actually viewportEvent is protected virtual. So I think I should be able to use that to route things to wherever I needed them. or ?
Please help, when you can and have time. :-) Thank you in advance!
Best Regards,
Laszlo PappEdit: Solved.
-
Could you please tell us how you solved it? That might be useful for future reference.
-
Sure, but you can check out the files aforementioned anytime or the commit message.
I stopped using the QGLWidget subclass as the viewport and I change the index in a QStackedWidget when I play or stop the game meaning that the default visible widget is the QDeclarativeView and when I click on the Play game in that screen, the game starts being played and I change the index to the QGLWidget inside the QStackedWidget and vica versa when I stop playing the game.