【问题标题】:How to draw a transparent rectangle with colored corners in qt?如何在qt中绘制一个带彩色角的透明矩形?
【发布时间】:2019-01-31 05:34:38
【问题描述】:

如何在 qt 中绘制一个带彩色角的透明矩形(使用 QPainter),如下图所示:

【问题讨论】:

    标签: c++ qt qpainter


    【解决方案1】:
    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)));
    }
    

    【讨论】:

    • 非常好,只是对您已注释掉的fillRect() 的评论:如果您想填充该区域,请在绘制角之前完成。否则,填充矩形将覆盖线条的“内”半部分。
    猜你喜欢
    • 2012-06-20
    • 1970-01-01
    • 2020-10-09
    • 1970-01-01
    • 2016-12-04
    • 1970-01-01
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多