1.QDialog,QWidget实现圆角,圆弧边框
注意设置使用setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint),去掉dialog的标题栏显示。
在QDialog的的resizeEvent时间中添加一下代码:
void CDemoDlg::resizeEvent(QResizeEvent* e)
{
QBitmap bmp(size());
bmp.fill();
QPainter p(&bmp);
p.setRenderHint(QPainter::Antialiasing);
//p.drawRoundedRect(bmp.rect(), 20, 20); //四个角都是圆弧
//只要上边角圆弧
int arcR = 10; //圆弧大小
QRect rect = this->rect().adjusted(0, 0, 0, 0);
QPainterPath path;
//逆时针
path.moveTo(arcR, 0);
//左上角
path.arcTo(0, 0, arcR * 2, arcR * 2, 90.0f, 90.0f);
path.lineTo(0, rect.height()-arcR);
//左下角
path.arcTo(0, rect.height() - arcR * 2 , arcR * 2, arcR * 2, 180.0f, 90.0f);
path.lineTo(rect.width(), rect.height());
//右下角
path.arcTo(rect.width() - arcR * 2, rect.height() - arcR * 2 , arcR * 2, arcR * 2, 270.0f, 90.0f);
path.lineTo(rect.width(), arcR);
//右上角
path.arcTo(rect.width() - arcR * 2, 0, arcR * 2, arcR * 2, 0.0f, 90.0f);
path.lineTo(arcR, 0);
p.drawPath(path);
//此行代码必须添加,不然无法达到正常的显示
p.fillPath(path, QBrush(Qt::red));
setMask(bmp);
return QDialog::resizeEvent(e);
}