简体   繁体   English

如何在Qt中绘制带有彩色角的透明矩形?

[英]How to draw a transparent rectangle with colored corners in qt?

How to draw a transparent rectangle with colored corners in qt(using QPainter), like this one in the below image : 如何在Qt中使用QPainter绘制一个带有彩色角的透明矩形,如下图所示:

在此处输入图片说明

void Widget::paintEvent(QPaintEvent *) {
    draw(10,10,50,50);
}

void Widget::draw(int x,int y,int _width,int _height)
{
    QPainter p(this);
    p.setPen(QPen(Qt::red,3,Qt::SolidLine));
    p.drawLine(x,y,x +0,_height/4+y);
    p.drawLine(x,y+ _height,x + 0,_height - _height/4+y);
    p.drawLine(x,y,x +_width/4,0+y);
    p.drawLine(x,y+_height,x +_width/4,_height+y);
    p.drawLine(_width+x,y+_height,x +_width - _width/4,_height+y);
    p.drawLine(_width+x,y+_height,x +_width,_height - _height/4+y);
    p.drawLine(_width+x,y,x + _width-_width/4,0+y);
    p.drawLine(_width+x,y,_width+x,_height/4+y);
    //custom brush for rectangle
    //p.fillRect(x,y,_width,_height,QBrush(QColor(40,0,0,50)));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM