c++ - 如何在qt中绘制带彩色角的透明矩形?

标签 c++ qt qpainter

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

enter image description here

最佳答案

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)));
}

关于c++ - 如何在qt中绘制带彩色角的透明矩形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54453944/

相关文章:

qt4 - 如何使 QImage 或 QPixmap 半透明 - 或者为什么 setAlphaChannel 过时?

c++ - "#include&lt"和#include之间的区别”

c++ - 欧拉计划问题 17 - 怎么了?

c++ - OpenGL-QT : Mouse move event effects is not showing up

c++ - 在小部件中居中 QGraphicsView

c++ - 在 QPainter::end() 之前调用 QImage::save() 是否安全

c++ - 在不知道派生类的情况下从父类调用派生类函数

c++ - 如何在调整大小时保持相同的场景部分可见?

c++ - 使 Qt 应用程序在最后一个窗口关闭时不退出

c++ - 是否可以设置全局 QPainter 默认渲染提示?