Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is there a way to keep a widget on top of other windows without stealing focus?
Forum Updated to NodeBB v4.3 + New Features

Is there a way to keep a widget on top of other windows without stealing focus?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 5.4k Views 1 Watching
  • 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.
  • pavel_abrP Offline
    pavel_abrP Offline
    pavel_abr
    wrote on last edited by pavel_abr
    #1

    Hello all,

    I'm writing an application for OSX/Windows that will basically hover as a small box on top of other applications without stealing focus (but can be interacted with). Using

    webview->setWindowFlags(
           Qt::WindowStaysOnTopHint |
           Qt::Dialog);
    

    And a loop that constantly calls webview->raise() once per second seems to work well on windows. If the user uses something like powerpoint, the slides will work without hiding the tool or stealing focus from the slides.

    The loop sort of looks like this:

    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(goTop()));
    timer->start(1000);
    

    However, on OSX the raise() function steals focus from all the other applications. This is very annoying. Without the loop, the tool gets blocked out by other services trying to go full screen (like LibreOffice presentation slides).

    I know NSWindow has makeKeyAndOrderFront(_:), which brings the window to the front, but doesn't focus it. Is there some something similar implemented with QT 5? Is this a potential ethical problem as well?

    Any help is appreciated.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      The point of using Qt::WindowStaysOnTopHint is so that it will stay on top, without the need to call raise() periodically.

      Does that flag alone not work for you?

      (Z(:^

      pavel_abrP 1 Reply Last reply
      0
      • sierdzioS sierdzio

        The point of using Qt::WindowStaysOnTopHint is so that it will stay on top, without the need to call raise() periodically.

        Does that flag alone not work for you?

        pavel_abrP Offline
        pavel_abrP Offline
        pavel_abr
        wrote on last edited by pavel_abr
        #3

        @sierdzio Hi, thank you for responding! Yes that flag works on its own when placing the view over say Microsoft PowerPoint slides, but does not work when the widget is floating over Keynote slides (this is my main use case). My feeling is that I'm basically fighting an "on top" war with the other application, which may be using its own native version of "on top".

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Ah I see, that looks likely.

          As far as I know, Qt does not offer a wrapper around makeKeyAndOrderFront(), but nothing is stopping you from using it. A bit of platform-dependent code is not a crime :-)

          Also, since you have found that raise() causes different behaviour on Windows and Mac, please consider reporting it as a bug to Qt bugtracker.

          (Z(:^

          pavel_abrP 1 Reply Last reply
          0
          • sierdzioS sierdzio

            Ah I see, that looks likely.

            As far as I know, Qt does not offer a wrapper around makeKeyAndOrderFront(), but nothing is stopping you from using it. A bit of platform-dependent code is not a crime :-)

            Also, since you have found that raise() causes different behaviour on Windows and Mac, please consider reporting it as a bug to Qt bugtracker.

            pavel_abrP Offline
            pavel_abrP Offline
            pavel_abr
            wrote on last edited by
            #5

            @sierdzio Thanks for the reply. Any chance you could point me in the right direction for how to access the underlying native view. Does QT expose that in some way?

            Also, another big difference appears to be in how Qt::WindowStaysOnTopHint treats full screen browsers on Windows versus OSX. On windows, the widget stays on top of full screened youtube and other pages. On OSX, the widget is pushed out of the way. If this kind of behaviour difference warrants a bug report, I can file that as well.

            Cheers

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              I rarely code on Macs so I can't help you with anything specific.

              Some things that might point you in the right direction:

              • try setting your widget's window flags to Qt::Tool
              • take a look at effectiveWinId()
              • check out QMacNativeWidget
              • and lastly, maybe Mac extras module has some helpers for that: link

              About the bug report: in my view, this is indeed a bug worth reporting. However, since Mac window manager is so unusual, maybe this behaviour is simply inavoidable/ intentional. If so, at least the docs should be updated to warn people about it and suggest workarounds.

              (Z(:^

              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