Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Focus does not return to QMainWindow after closing any modal QDialog until clicked with mouse



  • My Qt5 desktop application shows a modal dialog right after showing the main window. The main window is shown as full screen with Qt::FramelessWindowHint flag. The problem is when I close the dialog, the focus does not return to the main window. This is true for any dialog opened subsequently in the application.

    A particular button on the main window is supposed to have focus and is set by calling QWidget::setFocus(). But still the focus is not visible on that button (highlight with a different color on focus). I also observed that QApplication::activeWindow() returns NULL at this point. The focus is seen only when an empty area of the main window is clicked with mouse. This makes it difficult to work with keyboard only.

    There is no issue when deployed on Windows and Ubuntu and it works perfectly. But the problem is observed when deployed on Yocto Linux.

    Yocto Linux is running without a Window Manager and Desktop Environment. Can this be an issue for the window not to get activated automatically?



  • @coonal Hi, I don't know anything about that particular Linux flavour however when you dig into Qt::WindowType enum you can see two values:

    Qt::FramelessWindowHint	0x00000800	Produces a borderless window. The user cannot move or resize a borderless window via the window system. On X11, the result of the flag is dependent on the window manager and its ability to understand Motif and/or NETWM hints. Most existing modern window managers can handle this.
    

    and

    Qt::X11BypassWindowManagerHint	BypassWindowManagerHint	Bypass the window manager completely. This results in a borderless window that is not managed at all (i.e., no keyboard input unless you call QWidget::activateWindow() manually).
    

    Judging by the behaviour something is not handled right in the window manager, that would be my guess at least considering that it does work on more popular platforms.



  • @artwaw it seems WM is not running on his platform. do you mean it has to be managed by the app in that case?



  • @bg20 I am sorry to say but that beats me. Not a case I ever had to deal with.
    EDIT: quick work around I can think of is to set the focus via code upon closing the dialog, that can work 100%


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    @bg20 said in Focus does not return to QMainWindow after closing any modal QDialog until clicked with mouse:

    @artwaw it seems WM is not running on his platform. do you mean it has to be managed by the app in that case?

    It depends on how you configured your yocto image and the backend used for Qt.



  • This post is deleted!


  • @SGaist is there a way configuration for yocto and QT's backend can be checked on running yocto machine?


  • Lifetime Qt Champion

    You have to check with the Yocto documentation.

    Use the QT_DEBUG_PLUGINS environment variable set to 1 and you'll have the information about what is being loaded by your application.


Log in to reply