vin*_*nes 5 c++ winapi qt transparent mousewheel
我有一个最简单的测试用例应用程序:
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!
}
Run Code Online (Sandbox Code Playgroud)
主要.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();
}
Run Code Online (Sandbox Code Playgroud)
不透明小部件仅报告何时获得鼠标单击和滚轮事件。透明小部件覆盖不透明小部件。
鼠标点击按预期工作:
无论滚轮事件发生在何处,透明小部件都会捕获它们。相同的设置用于 Qt4.8。这是Qt5的一个bug吗?有什么可能的解决方法吗?
类似问题的解决方案似乎也不起作用: How to create a semi transparent window in WPF that allowed mouse events to pass through
(Qt 5.6.1、Windows 10)