QT 入门(无边框窗口拖拽 窗体透明 阴影)

论坛 期权论坛 脚本     
已经匿名di用户   2022-7-2 22:16   4102   0

1 隐藏window默认边框

setWindowFlags(Qt::FramelessWindowHint | windowFlags());

2 重写鼠标进入事件 鼠标松开函数 鼠标移动事件 声明

virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);

3 实现

void MainWindow::mouseMoveEvent(QMouseEvent * event)
{
 QPoint mousePoint = event->globalPos();
 QPoint point = mousePoint - z;
 this->move(point);
}

void MainWindow::mousePressEvent(QMouseEvent * event)
{
 QPoint mousePoint = event->globalPos();
 QPoint topPoint = this->geometry().topLeft();
 z = mousePoint - topPoint;
}

void MainWindow::mouseReleaseEvent(QMouseEvent * event)
{
 this->z = QPoint();
}

4 设置窗口阴影 无法设置主窗口

QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect();
shadowEffect->setBlurRadius(10); //设置圆角半径 像素
shadowEffect->setColor(Qt::black); // 设置边框颜色
shadowEffect->setOffset(0);

this->ui.shadowWidget->setGraphicsEffect(shadowEffect);

5 设置主窗口透明

this->setAttribute(Qt::WA_TranslucentBackground);

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP