简体   繁体   English

Qt5,透明窗口和车轮事件

[英]Qt5, transparent window and wheel events

I have a simplest test case application: 我有一个最简单的测试用例应用程序:

TransWidget.cpp: 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: 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. 用于Qt4.8的相同设置。 Is it a bug in Qt5? 这是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 类似问题的解决方案似乎也不起作用: 如何在WPF中创建一个允许鼠标事件通过的半透明窗口

(Qt 5.6.1, Windows 10) (Qt 5.6.1,Windows 10)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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