2 Star 4 Fork 2

GreateCoder/Message_Center

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
shadowwidget.cpp 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
GreateCoder 提交于 2015-10-23 17:45 +08:00 . 第一次提交
#include "shadowwidget.h"
#include <QPainter>
#include <QMouseEvent>
#include <QStyleOption>
#include <qmath.h>
ShadowWidget::ShadowWidget(QWidget *parent) :
QWidget(parent), m_mousePress(false)
{
setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint|Qt::Tool);
//this->setObjectName("basewidget");
// setAttribute(Qt::WA_TranslucentBackground);
}
void ShadowWidget::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
//加阴影,因为扁平化去掉
// QPainterPath path;
// path.setFillRule(Qt::WindingFill);
// path.addRect(10, 10, this->width()-20, this->height()-20);
// QPainter painter(this);
// painter.setRenderHint(QPainter::Antialiasing, true);
// painter.fillPath(path, QBrush(Qt::white));
// QColor color(0, 0, 0, 50);
// for(int i=0; i<10; i++)
// {
// QPainterPath path;
// path.setFillRule(Qt::WindingFill);
// path.addRect(10-i, 10-i, this->width()-(10-i)*2, this->height()-(10-i)*2);
// color.setAlpha(150 - qSqrt(i)*50);
// painter.setPen(color);
// painter.drawPath(path);
// }
}
void ShadowWidget::mousePressEvent(QMouseEvent *event)
{
//只能是鼠标左键移动和改变大小
if(event->button() == Qt::LeftButton)
{
m_mousePress = true;
}
//窗口移动距离
m_movePoint = event->globalPos() - pos();
}
void ShadowWidget::mouseReleaseEvent(QMouseEvent *)
{
m_mousePress = false;
}
void ShadowWidget::mouseMoveEvent(QMouseEvent *event)
{
//移动窗口
if(m_mousePress)
{
QPoint movePpos = event->globalPos();
move(movePpos - m_movePoint);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/GreateCoder/Message_Center.git
[email protected]:GreateCoder/Message_Center.git
GreateCoder
Message_Center
Message_Center
master

搜索帮助