Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] Set the focus on the viewport of the QDeclarativeView
Forum Update on Monday, May 27th 2025

[SOLVED] Set the focus on the viewport of the QDeclarativeView

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    djszapi
    wrote on last edited by
    #1

    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#L83

    I 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#L62

    I 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#L137

    Everything 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 Papp

    Edit: Solved.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Could you please tell us how you solved it? That might be useful for future reference.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        djszapi
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved