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. Setting or unsetting the Qt::WindowTransparentForInput flag on the main window causes the window to hide

Setting or unsetting the Qt::WindowTransparentForInput flag on the main window causes the window to hide

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 437 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.
  • L Offline
    L Offline
    Lucas64_t
    wrote on last edited by
    #1

    I have an application where you can toggle on a feature to make the main window transparent for inputs. However, while the user holds the Alt-key, then the window can receive inputs again. My problem is that whenever I set or unset the Qt::WindowTransparentForInput flag, the main window sets its visibility to false. I then have to manually turn the visibility back on. It is unfortunately still very much noticable that the window hides for a moment. Does somebody know what causes the window to hide and if there is a way to prevent that?

    In the main window constructor I set these flags

    setWindowFlag(Qt::FramelessWindowHint, true);
    setWindowFlag(Qt::WindowStaysOnTopHint);
    setAttribute(Qt::WA_TranslucentBackground, true);
    

    This is the function which sets or unsets the Qt::WindowTransparentForInput flag. When the feature is enabled, this function is called every 100 miliseconds, based on a QTimer.

    void MainWindow::checkHoldKeyState()
    {
        bool held = qApp->queryKeyboardModifiers().testFlag(Qt::AltModifier); // is the Alt-key held?
        Qt::WindowFlags flags = windowFlags();
        bool transparent = flags & Qt::WindowTransparentForInput; // is the WindowTransparentForInput flag set?
        if(held == transparent)
        {
            // If the Alt-key is held and the flag is set, remove the flag.
            // If the Alt-key is not held and the flag is not set, apply the flag.
            setWindowFlag(Qt::WindowTransparentForInput, !transparent);
        }
    
        if(isHidden()) // When the WindowTransparentForInput flag was set or unset, the window always is hidden.
        {
            show(); // Setting the window to visible again causes flickering
        }
    }
    
    1 Reply Last reply
    0
    • L Offline
      L Offline
      Lucas64_t
      wrote on last edited by
      #2

      Interestingly this does not affect the visibility of a QDialog which is a direct child of the main window.

      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