Qt去边框边缘阴影效果

        在很多时候,我们不需要Qt自带的窗口边框, 我们都会去掉它实现自己想要的窗口边框,但是,去掉边框之后,边缘阴影效果随之不见,总感觉光秃秃的不舒服,所以下面是几个去边框加边缘阴影效果的方法。

第一种  使用Qt的QGraphicsDropShadowEffect类来实现。

#include "widget.h"
#include "ui_widget.h"
#include <QHBoxLayout>
#include <QGraphicsDropShadowEffect>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    resize(400, 300);
    setWindowFlags(windowFlags() | Qt::FramelessWindowHint); // 其中windowFlags()函数返回当前窗口的标志
    setAttribute(Qt::WA_TranslucentBackground); // 设置窗口背景透明,其中Qt::WA_TranslucentBackground 是表示窗口背景透明的一个属性。
    QWidget *widget = new QWidget(this);
    widget->setStyleSheet("background-color: white");
    QHBoxLayout *pLayout = new QHBoxLayout(this);
    pLayout->addWidget(widget);
    pLayout->setContentsMargins(20, 20, 20, 20);

    QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(widget);
    shadow->setOffset(0, 0);
    shadow->setColor(QColor(QStringLiteral("black")));
    shadow->setBlurRadius(30);
    widget->setGraphicsEffect(shadow);

}

第二种  使用Qt的QGraphicsDropShadowEffect类来实现。

        还有几种方式,现在不想写了,以后再写。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值