qt--mask蒙版

 

复制代码
    this->resize(500,300);
    QLabel* label=new QLabel("标签",this);
    label->move(10,10);
    QLabel* label1=new QLabel("标签",this);
    label1->move(250,10);
    QPixmap p("./a.png");
    label->setPixmap(p);
    label->resize(p.size());

    //QPixmap m("./m.png");  //载入蒙版图片--方法一
    //注意:不想显示的部分必须ps成透明

    QBitmap m("./mb.png");  //载入蒙版图片--方法二
    //注意:不想显示的部分必须ps成白色,想显示的部分ps成黑色

    label1->setPixmap(m);
    //label->setMask(m.mask()); //设置蒙版--对应方法一
    label->setMask(m);  //设置蒙版--对应方法二
复制代码

上面工程下载: 链接:https://pan.baidu.com/s/1fCoMOwF-kcsSAL6b2_SElA    提取码:6666    

 

蒙版实例--不规则按钮

复制代码
    this->resize(400,300);
    QPushButton* button=new QPushButton("按钮",this);
    QPixmap p("./a.png");
    button->move(10,10);
    button->resize(p.size());
    //button->setStyleSheet("background-image:url(./a.png);");
    button->setStyleSheet("QPushButton{background:url(./a.png);border:0px;}"  //按钮的三种状态
        "QPushButton:hover{background:url(./b.png);border:0px}"
        "QPushButton:pressed{background:url(./c.png); position: relative;top: 1px; left: 1px;}");
    QBitmap m("./m.png");

    button->setMask(m);
复制代码

效果图:

 

 

 工程下载:链接:https://pan.baidu.com/s/1LQlJXXsMWxdpz45xkZEqsw   提取码:6666   

 

 

 

posted @   天子骄龙  阅读(841)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示