12345678910111213141516171819202122232425262728293031323334353637383940 |
- #include "shadowwidget.h"
- #include <QLayout>
- #include <QGraphicsDropShadowEffect>
- #include <QDebug>
- ShadowWidget::ShadowWidget(QWidget *parent)
- : QWidget(parent)
- , m_pCentralWidget(new QWidget(this))
- {
- setWindowFlags(Qt::FramelessWindowHint);
- setAttribute(Qt::WA_TranslucentBackground);
- QHBoxLayout* pLayout = new QHBoxLayout();
- if (nullptr != pLayout) {
- pLayout->addWidget(m_pCentralWidget);
- this->setLayout(pLayout);
- }
- QGraphicsDropShadowEffect *pShadowEffect = new QGraphicsDropShadowEffect(this);
- pShadowEffect->setBlurRadius(16); // 模糊度
- pShadowEffect->setColor(QColor(0, 0, 0, 90)); // 阴影的颜色
- pShadowEffect->setOffset(0, 0); // 水平和垂直偏移量
- m_pCentralWidget->setGraphicsEffect(pShadowEffect);
- }
- void ShadowWidget::setCentralLayout(QLayout *layout)
- {
- if (nullptr != m_pCentralWidget) {
- m_pCentralWidget->setLayout(layout);
- }
- }
- QLayout* ShadowWidget::getLayout() const
- {
- if (nullptr != m_pCentralWidget) {
- return m_pCentralWidget->layout();
- }
- return nullptr;
- }
|