简体   繁体   中英

Qt5, transparent window and wheel events

I have a simplest test case application:

TransWidget.cpp:

TransWidget::TransWidget(QWidget *parent) :
    QWidget(parent, Qt::Window | Qt::FramelessWindowHint)
{
    setAttribute(Qt::WA_ShowWithoutActivating);
    setAttribute(Qt::WA_TransparentForMouseEvents);
    setAttribute(Qt::WA_TranslucentBackground);
}

void TransWidget::paintEvent(QPaintEvent *)
{
    // some code to mark the presence of the window
}

void TransWidget::wheelEvent(QWheelEvent * ev)
{
    ev->ignore(); // keeps getting here no matter what I try!
}

main.cpp:

#include "TransWidget.h"
#include "OpaqueWidget.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    OpaqueWidget o;
    auto t = new TransWidget(&o);

    o.show();
    t->show();

    return a.exec();
}

Opaque widget simply reports when it gets mouse clicks and wheel events. Transparent widget overlays the opaque widget.

Mouse clicks work as expected:

  • fall through transparent regions to the opaque widget;
  • get caught by transparent widget when clicked in its painted (thus opaque) areas.

Wheel events get caught by the transparent widget no matter where they occur. The same setup used to work with Qt4.8. Is it a bug in Qt5? Any workarounds possible?

The solution to a similar question doesn't seem to work also: How to create a semi transparent window in WPF that allows mouse events to pass through

(Qt 5.6.1, Windows 10)

作为Qt错误被接受,请参阅https://bugreports.qt.io/browse/QTBUG-53418了解详细信息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM