views:

445

answers:

2

When i click a button my main window i want it to become transparent to keyboard and mouse events, i.e. all keyboard and mouse events should pass to any windows below it as if that window is not present there.

"Qt::WA_TransparentForMouseEvents" does not work here as this only make child windows transparent to keyboard and mouse events i guess. And my window is main window and i want to pass all event to any window on desktop not just parent window.

A: 

Hello,

I have been using Qt::WA_TransparentForMouseEvents in my application and it works great.

I dont understand the problem you are facing and it should work. If you still have problem setattribute to Qt::WA_TransparentForMouseEvents and Qt::WA_Translucentbackground.

I hope it will solve you problem.

Thanks, Rahul

Rahul
have u ever used "WS_EX_TRANSPARENT" in MFC, i want some thing similar to this.what this(Qt::WA_TransparentForMouseEvents) does is make child transparent to mouse event and will send all child events to parent, but what if my window which i want to make mouse event transparent is top level window or say is my Main Window. this flag does not seem to work there.when we use setWindowOpacity(0.0), all events go through it, but problem is even what ever i draw on it also becomes invisible(transparent window), but i want drawings on it to be visible and still mouse events should go through it.
Gajender
A: 

Here is the sample code which enables me to do drawing on and still mouse events go through it.

Sample::Sample(QWidget *pParent):QWidget(pParent)
{
    setAttribute(Qt::WA_TranslucentBackground);
    setAttribute(Qt::WA_TransparentForMouseEvents);
    setWindowFlags(Qt::FramelessWindowHint);
    QDesktopWidget qDesktopWidget;
    QRect screenSize = qDesktopWidget.screenGeometry();
    setGeometry(screenSize);
}

Sample::~Sample()
{
}

void Sample::paintEvent(QPaintEvent*)
{
    QDesktopWidget new QDesktopWidget();
    QRect rectangle = qDesktopWidget->screenGeometry();
    setGeometry(rectangle);

    const QPoint points[5] = {
        QPoint(0, 20),
        QPoint(rectangle.width(), 20),
        QPoint(rectangle.width(), rectangle.height()),
        QPoint(0,rectangle.height()),
        QPoint(0, 0)
    };

    QPen pen(Qt::blue, 10, Qt::SolidLine, Qt::SquareCap);
    QPainter painter(this);
    painter.setPen(pen);
    painter.drawPolyline(points, 5);
    painter.end();
}
Rahul
Rahul, what u did here has made window translucent even if we don't set transparentForMouse flag and also mouse events go through, but when we set flag "WindowStaysOnTopHint" transparency goes away. and one more problem with it is it just give mouse transparency to area which is transparent not to full window, drawn area still have mouse.This kind of behavior can even be attained by using SetMask() on widget and using a alpha blended image.but what i want is to make all events go through, keyboard mouse and all.drawing will always be visible to user,in ur case window goes to background also.
Gajender

related questions