Click through windows

  • Hi,

    How do I create a transparent window with mouse events going through the window? Actually I try to set transparency with this in the constructor:

    setAttribute(Qt::WA_TranslucentBackground, true);

    But it only works on linux, under Windows I get a black background and I still don't know how to make mouse click going through my window.
    I hope someone will know how to fix it :)

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Looks like you want: widget->setAttribute(Qt::WA_TransparentForMouseEvents).

  • @SGaist I already try it:

    here is my code:

    #include "transparentwindow.h"
    TransparentWindow::TransparentWindow() : QWidget()
        setFixedSize(300, 150);
        m_b= new QPushButton("Ok", this);
        setAttribute(Qt::WA_NoSystemBackground, true);
        setAttribute(Qt::WA_TranslucentBackground, true);

    header of the file:

    #include <QObject>
    #include <QWidget>
    #include <QPushButton>
    class TransparentWindow : public QWidget
        QPushButton *m_b;
    and my main.cpp:

    #include <iostream>
    #include <QApplication>
    #include <transparentwindow.h>

    int main(int argc, char**argv)
    QApplication app(argc, argv);
    TransparentWindow f;;

    return app.exec();


    but here is the result:

  • Qt Champions 2016

    Being drawn transparently or have mouse event passthrough is not the same.
    Anyway, i used this to have a 100% invisible window and clicks went through it.
    (win 10, not tried on linux)

    class Overlay : public QWidget {
      explicit Overlay ( QWidget* parent = 0 ) :
        QWidget ( parent ) {
        setPalette ( Qt::transparent );
        setAttribute ( Qt::WA_TransparentForMouseEvents );
      void paintEvent ( QPaintEvent* event ) {} // draw nothing ( i did draw some stuff) not 100% sure its needed.

  • @mrjj I simply copy/paste your code but I still get the same result: a black window and the click don't go through the window (I try it on both Windows and linux).

  • Qt Champions 2016


    Works here. (win 10)
    You can try my sample

  • Well your project don't work for my, perhaps because I am using a 64 bits Windows 7 on virtual machine and compiling my project in 32 bits. But anyway I find a solution on another forum, here.

    here the constructor of my transparent and click-through window:

    MyWindows::MyWindows() : QWidget()
        setAttribute(Qt::WA_TranslucentBackground, true);
        setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); //we can add Qt::Tool

    so thanks everyone for your help!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.