忘记、过去
2023-08-04 02:00 deepin
QWidget::setAttribute(Qt::WA_TransparentForMouseEvents, true)
试试看?
P.S. 我记得在 Deepin 20 很早的版本上,一个无边框的 QWidget 如果设置背景色为全透明,默认就是鼠标穿透的效果......
Reply Like 0 View the author
QWidget::setAttribute(Qt::WA_TransparentForMouseEvents, true)
试试看?
P.S. 我记得在 Deepin 20 很早的版本上,一个无边框的 QWidget 如果设置背景色为全透明,默认就是鼠标穿透的效果......
#include
#include
#include
#include
#include
#include
class TransparentWidget : public QWidget
{
public:
TransparentWidget(QWidget *parent = nullptr) : QWidget(parent)
{
//setMouseTracking(true);
setAttribute(Qt::WA_TransparentForMouseEvents, true);
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowTransparentForInput);
setAttribute(Qt::WA_TranslucentBackground, true);
//QLabel *label = new QLabel("Hello, World!", this);
//label->setAlignment(Qt::AlignCenter);
//label->resize(200, 100);
}
protected:
void mouseMoveEvent(QMouseEvent *event) override
{
qDebug() << "Mouse move event at" << event->pos();
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
TransparentWidget widget;
widget.resize(400, 300);
widget.show();
return app.exec();
}
#include
#include
#include
#include
#include
#include
class TransparentWidget : public QWidget
{
public:
TransparentWidget(QWidget *parent = nullptr) : QWidget(parent)
{
//setMouseTracking(true);
setAttribute(Qt::WA_TransparentForMouseEvents, true);
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowTransparentForInput);
setAttribute(Qt::WA_TranslucentBackground, true);
//QLabel *label = new QLabel("Hello, World!", this);
//label->setAlignment(Qt::AlignCenter);
//label->resize(200, 100);
}
protected:
void mouseMoveEvent(QMouseEvent *event) override
{
qDebug() << "Mouse move event at" << event->pos();
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
TransparentWidget widget;
widget.resize(400, 300);
widget.show();
return app.exec();
}
设置都没问题,但是就是没效果
直接白嫖DTK啊,默认就是无边框的效果
Popular Ranking
ChangePopular Events
More
有没有大佬能提供一个鼠标穿透的程序的思路,Python,c, QT都可以,我在deepin和uos用了各种办法尝试做一个透明无边框,鼠标穿透效果的窗口,但都失败了,窗口显示都没有问题,鼠标穿透不行。