1.设置setStyleSheet
setStyleSheet("border:1px solid #FFFFFF");
其他的样式介绍如下:
font: bold; 是否粗体显示
font-family:""; 来设定字体所属家族,
font-size:20px; 来设定字体大小
font-style: nomal; 来设定字体样式
font-weight:20px; 来设定字体深浅
color:black ;字体颜色
border: 1px solid gray;边框大小,样式,颜色
border-image:""; 用来设定边框的背景图片。
border-radius:5px; 用来设定边框的弧度。可以设定圆角的按钮
border-width: 1px; 边框大小
background-color: green; 设置背景颜色
background:transparent; 设置背景为透明
color:rgb(241, 70, 62); 设置前景颜色
selection-color:rgb(241, 70, 62); 用来设定选中时候的颜色
2.重写paintEvent
首先widget设置
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
void RotateWidget::paintEvent(QPaintEvent *event)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.addRoundedRect(0, 0, this->width(), this->height(), 2, 2);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.fillPath(path, QBrush(QColor(230,230,230)));
// 给垂直布局器设置边距(此步很重要, 设置宽度为阴影的宽度)
this->setContentsMargins(1,1,1,1);
}
3.QGraphicsDropShadowEffect
首先widget设置
//设置窗体透明
this->setAttribute(Qt::WA_TranslucentBackground, true);
//设置无边框
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
//实例阴影shadow
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
//设置阴影距离
shadow->setOffset(0, 0);
//设置阴影颜色
shadow->setColor(QColor("#444444"));
//设置阴影圆角
shadow->setBlurRadius(30);
//给嵌套QWidget设置阴影
this->setGraphicsEffect(shadow);
//给垂直布局器设置边距(此步很重要, 设置宽度为阴影的宽度)
this->setContentsMargins(1,1,1,1);