qt绘制试剂瓶

效果:
在这里插入图片描述
代码:

            painter.setPen(QPen(QColor(0, 0, 0,100), 3));
            int w = ui->wdtKit->width();
            int h = ui->wdtKit->height();
            //绘制瓶盖
            QRect rectCap(w/2,1,w/2-4,h/4);
            QBrush brushCap(QColor(0, 0, 0, 100), Qt::VerPattern);
            painter.setBrush(brushCap);
            painter.drawRoundedRect(rectCap,2,2);
            //绘制瓶颈
            painter.drawLine(QPoint(w*5/8,h/4+1),QPoint(w*5/8,h*0.33-1));
            painter.drawLine(QPoint(w*7/8,h/4+1),QPoint(w*7/8,h*0.33-1));
            //绘制瓶身
            QRect rectBottle(1,h*0.33,w-2,h*0.66-1);
            painter.setBrush(QBrush(Qt::NoBrush));
            painter.drawRoundedRect(rectBottle,3,3);
            //擦除瓶颈位置
            painter.setBrush(QBrush(colorbkg, Qt::Dense1Pattern));
            painter.setPen(QPen(colorbkg, 0));
            painter.drawRect(w*5/8,h*0.33-2,w/4,4);

おすすめ

転載: blog.csdn.net/weixin_42887343/article/details/120904127