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