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 @ 2020-10-31 20:17  天子骄龙  阅读(750)  评论(0编辑  收藏  举报