[software development] 鼠标穿透
Tofloor
poster avatar
181******28
deepin
2023-08-04 00:52
Author

有没有大佬能提供一个鼠标穿透的程序的思路,Python,c, QT都可以,我在deepin和uos用了各种办法尝试做一个透明无边框,鼠标穿透效果的窗口,但都失败了,窗口显示都没有问题,鼠标穿透不行。

Reply Favorite View the author
All Replies
忘记、过去
deepin
2023-08-04 02:00
#1

QWidget::setAttribute(Qt::WA_TransparentForMouseEvents, true) 试试看?

P.S. 我记得在 Deepin 20 很早的版本上,一个无边框的 QWidget 如果设置背景色为全透明,默认就是鼠标穿透的效果......

Reply View the author
181******28
deepin
2023-08-04 03:17
#2
#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();
}
Reply View the author
181******28
deepin
2023-08-04 03:17
#3
181******28
#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();
}

设置都没问题,但是就是没效果

Reply View the author
fuuko
deepin
2023-08-04 15:17
#4

直接白嫖DTK啊,默认就是无边框的效果

Reply View the author