資源簡(jiǎn)介
ShadowWidget 基于Qt5的去掉標(biāo)題欄之后添加邊框陰影的解決方案。 四種解決方法: 1. 如果是Windows平臺(tái),那么可以調(diào)用Windows相關(guān)API。 2. 使用Qt的QGraphicsDropShadowEffect類來(lái)實(shí)現(xiàn)。 3. 使用Qt的qDrawBorderPixmap函數(shù)來(lái)實(shí)現(xiàn)。 4. 自己構(gòu)造出邊框陰影QImage并繪制。
代碼片段和文件信息
/**
?*?去掉標(biāo)題之后添加邊框陰影
?*
?*?DrawBorderPixmapWidget.cpp
?*?使用Qt的qDrawBorderPixmap函數(shù)來(lái)實(shí)現(xiàn)陰影邊框的實(shí)現(xiàn)cpp文件。
?*
?*?FlyWM_
?*?GitHub:?https://github.com/FlyWM
?*?CSDN:?https://blog.csdn.net/a844651990
?*
?*/
#include?
#include?
#include?
#include?yleOption>
#include?
#include?“DrawBorderPixmapWidget.h“
DrawBorderPixmapWidget::DrawBorderPixmapWidget(QWidget?*parent)
????:?QWidget(parent)
{
????resize(400?300);
????setWindowFlags(Qt::framelessWindowHint);
????setAttribute(Qt::WA_TranslucentBackground);
}
void?DrawBorderPixmapWidget::paintEvent(QPaintEvent?*e)
{
????Q_UNUSED(e)
????QPainter?painter(this);
????QPixmap?pixmap(“:/client-shadow.png“);
????qDrawBorderPixmap(&painter?this->rect()?QMargins(8?8?8?8)?pixmap);
????//?繪制中心區(qū)域的背景色(不然會(huì)是透明的)
????QRect?rect(this->rect().x()+8?this->rect().y()+8?this->rect().width()-16?this->rect().height()-16);
????painter.fillRect(rect?QColor(255?255?255));
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件?????????25??2018-12-10?20:41??ShadowWidget\.git\COMMIT_EDITMSG
?????文件????????304??2018-12-10?20:22??ShadowWidget\.git\config
?????文件?????????73??2018-12-10?20:22??ShadowWidget\.git\desc
?????文件?????????99??2018-12-10?20:40??ShadowWidget\.git\FETCH_HEAD
?????文件?????????23??2018-12-10?20:22??ShadowWidget\.git\HEAD
?????文件????????478??2018-12-10?20:22??ShadowWidget\.git\hooks\applypatch-msg.sample
?????文件????????896??2018-12-10?20:22??ShadowWidget\.git\hooks\commit-msg.sample
?????文件???????3327??2018-12-10?20:22??ShadowWidget\.git\hooks\fsmonitor-watchman.sample
?????文件????????189??2018-12-10?20:22??ShadowWidget\.git\hooks\post-update.sample
?????文件????????424??2018-12-10?20:22??ShadowWidget\.git\hooks\pre-applypatch.sample
?????文件???????1642??2018-12-10?20:22??ShadowWidget\.git\hooks\pre-commit.sample
?????文件???????1348??2018-12-10?20:22??ShadowWidget\.git\hooks\pre-push.sample
?????文件???????4898??2018-12-10?20:22??ShadowWidget\.git\hooks\pre-reba
?????文件????????544??2018-12-10?20:22??ShadowWidget\.git\hooks\pre-receive.sample
?????文件???????1492??2018-12-10?20:22??ShadowWidget\.git\hooks\prepare-commit-msg.sample
?????文件???????3610??2018-12-10?20:22??ShadowWidget\.git\hooks\update.sample
?????文件???????2034??2018-12-10?20:41??ShadowWidget\.git\index
?????文件????????240??2018-12-10?20:22??ShadowWidget\.git\info\exclude
?????文件????????846??2018-12-10?20:41??ShadowWidget\.git\logs\HEAD
?????文件????????846??2018-12-10?20:41??ShadowWidget\.git\logs\refs\heads\master
?????文件????????175??2018-12-10?20:22??ShadowWidget\.git\logs\refs\remotes\origin\HEAD
?????文件????????548??2018-12-10?20:42??ShadowWidget\.git\logs\refs\remotes\origin\master
?????文件????????340??2018-12-10?20:27??ShadowWidget\.git\ob
?????文件????????645??2018-12-10?20:40??ShadowWidget\.git\ob
?????文件???????5137??2018-12-10?20:27??ShadowWidget\.git\ob
?????文件???????3038??2018-12-10?20:27??ShadowWidget\.git\ob
?????文件?????????47??2018-12-10?20:39??ShadowWidget\.git\ob
?????文件????????346??2018-12-10?20:27??ShadowWidget\.git\ob
?????文件???????2479??2018-12-10?20:27??ShadowWidget\.git\ob
?????文件???????3275??2018-12-10?20:27??ShadowWidget\.git\ob
............此處省略119個(gè)文件信息
評(píng)論
共有 條評(píng)論