企业网站必须备案吗/柳州网站建设
说明
我们知道QWidget等设置了this->setWindowFlags(Qt::FramelessWindowHint);
后无法移动和调整大小,但实际项目中是需要窗口能够调整大小的。所以以实现FrameLess弹窗调整大小及移动弹窗需求,并且在Windows 10上有Aero效果。
先看一下效果:
代码
大部分参考这个github。然后自己修改了一下,因为github上面的,在设置了qss后怎么也实现不了窗口圆角以阴影。下面修改版的代码可以实现圆角,但也没有阴影,只能在Widget中自己实现阴影了。
如果不需要圆角,github上面的也是会自带阴影的。不用下面的调整版实现方案。
#ifndef AEROMAINWINDOW_H
#define AEROMAINWINDOW_H#include <QMainWindow>class AeroMainWindow : public QMainWindow
{Q_OBJECTpublic:explicit AeroMainWindow(QWidget *parent = nullptr);~AeroMainWindow();//设置是否可以通过鼠标调整窗口大小//if resizeable is set to false, then the window can not be resized by mouse//but still can be resized programticallyvoid setResizeable(bool resizeable=true);bool isResizeable(){return m_bResizeable;}//设置可调整大小区域的宽度,在此区域内,可以使用鼠标调整窗口大小//set border width, inside this aera, window can be resized by mousevoid setResizeableAreaWidth(int width = 5);protected://设置一个标题栏widget,此widget会被当做标题栏对待//set a widget which will be treat as SYSTEM titlebarvoid setTitleBar(QWidget* titlebar);//在标题栏控件内,也可以有子控件如标签控件“label1”,此label1遮盖了标题栏,导致不能通过label1拖动窗口//要解决此问题,使用addIgnoreWidget(label1)//generally, we can add widget say "label1" on titlebar, and it will cover the titlebar under it//as a result, we can not drag and move the MainWindow with this "label1" again//we can fix this by add "label1" to a ignorelist, just call addIgnoreWidget(label1)void addIgnoreWidget(QWidget* widget);bool nativeEvent(const QByteArray &eventType, void *message, long *result);void resizeEvent(QResizeEvent *event);public slots:private slots:void onTitleBarDestroyed();private:QWidget *m_titleBar;QList<QWidget*> m_whiteList;int m_borderWidth;bool m_bResizeable;
};#endif // AEROMAINWINDOW_H
#include "aeromainwindow.h"#include <QGraphicsDropShadowEffect>
#include <QDesktopServices>
#include <QUrl>
#include <QGridLayout>
#include <QStyle>
#include <QDebug>
#include <QPushButton>#ifdef Q_OS_WIN
#include <windows.h>
#include <WinUser.h>
#include <windowsx.h>
#include <dwmapi.h>
#include <objidl.h> // Fixes error C2504: 'IUnknown' : base class undefined
#include <gdiplus.h>
#include <GdiPlusColor.h>
#pragma comment (lib,"Dwmapi.lib") // Adds missing library, fixes error LNK2019: unresolved external symbol __imp__DwmExtendFrameIntoClientArea
#pragma comment (lib,"user32.lib")
#endifAeroMainWindow::AeroMainWindow(QWidget *parent) :QMainWindow(parent),m_titleBar(Q_NULLPTR),m_borderWidth(5),m_bResizeable(true)
{this->setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明this->setWindowFlags(Qt::FramelessWindowHint); //设置无边框窗口this->setResizeable(true);
}AeroMainWindow::~AeroMainWindow()
{
}void AeroMainWindow::setResizeable(bool resizeable)
{bool visible = isVisible();m_bResizeable = resizeable;if (m_bResizeable){setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint);//此行代码可以带回Aero效果,同时也带回了标题栏和边框,在nativeEvent()会再次去掉标题栏////this line will get titlebar/thick frame/Aero back, which is exactly what we want//we will get rid of titlebar and thick frame again in nativeEvent() laterHWND hwnd = (HWND)this->winId();DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);::SetWindowLong(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CAPTION);}else{setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint);HWND hwnd = (HWND)this->winId();DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);::SetWindowLong(hwnd, GWL_STYLE, style & ~WS_MAXIMIZEBOX & ~WS_CAPTION);}//保留一个像素的边框宽度,否则系统不会绘制边框阴影const MARGINS shadow = { 1, 1, 1, 1 };DwmExtendFrameIntoClientArea(HWND(winId()), &shadow);setVisible(visible);
}void AeroMainWindow::setResizeableAreaWidth(int width)
{if (1 > width) width = 1;m_borderWidth = width;
}void AeroMainWindow::setTitleBar(QWidget* titlebar)
{m_titleBar = titlebar;if (!titlebar) return;connect(titlebar, SIGNAL(destroyed(QObject*)), this, SLOT(onTitleBarDestroyed()));
}void AeroMainWindow::onTitleBarDestroyed()
{if (m_titleBar == QObject::sender()){m_titleBar = Q_NULLPTR;}
}void AeroMainWindow::addIgnoreWidget(QWidget* widget)
{if (!widget) return;if (m_whiteList.contains(widget)) return;m_whiteList.append(widget);
}bool AeroMainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{MSG* msg = (MSG *)message;switch (msg->message){case WM_NCCALCSIZE:{//this kills the window frame and title bar we added with//WS_THICKFRAME and WS_CAPTION*result = 0;return true;} // WM_NCCALCSIZEcase WM_NCHITTEST:{*result = 0;const LONG border_width = m_borderWidth; //in pixelsRECT winrect;GetWindowRect(HWND(winId()), &winrect);long x = GET_X_LPARAM(msg->lParam);long y = GET_Y_LPARAM(msg->lParam);if(m_bResizeable){bool resizeWidth = minimumWidth() != maximumWidth();bool resizeHeight = minimumHeight() != maximumHeight();if(resizeWidth){//left borderif (x >= winrect.left && x < winrect.left + border_width){*result = HTLEFT;}//right borderif (x < winrect.right && x >= winrect.right - border_width){*result = HTRIGHT;}}if(resizeHeight){//bottom borderif (y < winrect.bottom && y >= winrect.bottom - border_width){*result = HTBOTTOM;}//top borderif (y >= winrect.top && y < winrect.top + border_width){*result = HTTOP;}}if(resizeWidth && resizeHeight){//bottom left cornerif (x >= winrect.left && x < winrect.left + border_width &&y < winrect.bottom && y >= winrect.bottom - border_width){*result = HTBOTTOMLEFT;}//bottom right cornerif (x < winrect.right && x >= winrect.right - border_width &&y < winrect.bottom && y >= winrect.bottom - border_width){*result = HTBOTTOMRIGHT;}//top left cornerif (x >= winrect.left && x < winrect.left + border_width &&y >= winrect.top && y < winrect.top + border_width){*result = HTTOPLEFT;}//top right cornerif (x < winrect.right && x >= winrect.right - border_width &&y >= winrect.top && y < winrect.top + border_width){*result = HTTOPRIGHT;}}}if (0 != *result) return true;//*result still equals 0, that means the cursor locate OUTSIDE the frame area//but it may locate in titlebar areaif (!m_titleBar) return false;//support highdpidouble dpr = this->devicePixelRatioF();QPoint pos = m_titleBar->mapFromGlobal(QPoint(x/dpr,y/dpr));if (!m_titleBar->rect().contains(pos)) return false;QWidget* child = m_titleBar->childAt(pos);if (!child){*result = HTCAPTION;return true;}else{if (m_whiteList.contains(child)){*result = HTCAPTION;return true;}}return false;} // WM_NCHITTESTdefault:return QMainWindow::nativeEvent(eventType, msg, result);}
}void AeroMainWindow::resizeEvent(QResizeEvent *event)
{if (m_titleBar)m_titleBar->setGeometry(QRect(0, 0, this->rect().width(), m_titleBar->rect().height()));QMainWindow::resizeEvent(event);
}
测试代码
生成一个类,继承上面的类。然后实现下面的内容。很简单:
#include "testmainwindow.h"
#include "ui_testmainwindow.h"TestMainWindow::TestMainWindow(QWidget *parent) :AeroMainWindow(parent),ui(new Ui::TestMainWindow)
{ui->setupUi(this);QWidget *titleBar = new QWidget(this);titleBar->setGeometry(QRect(0, 0, this->rect().width(), 25));this->setTitleBar(titleBar);this->setStyleSheet("background-color: red;\border-radius: 8px;");
}TestMainWindow::~TestMainWindow()
{delete ui;
}
相关文章:

[Qt]FrameLessWindow实现调整大小、移动弹窗并具有Aero效果
说明 我们知道QWidget等设置了this->setWindowFlags(Qt::FramelessWindowHint);后无法移动和调整大小,但实际项目中是需要窗口能够调整大小的。所以以实现FrameLess弹窗调整大小及移动弹窗需求,并且在Windows 10上有Aero效果。 先看一下效果…...

【API生命周期看护】API日落
一、基本概念 在API的整个生命周期中,不可能是永远不变的。功能可能有变动、服务也可能有升级迭代,这个时候对外的能力入口:API自然也需要改变。 一般来说,API的变动是不可以引入兼容性问题的,也即不管做什么变动&am…...

PHP 使用ThinkPHP实现电子邮件发送示例
文章目录 首先我们需要设置我们的邮箱客户端授权,获取到授权码找到我们的邮箱设置去账号中找到这一堆服务,找到后开启smtp服务开启服务后管理服务 接下来需要去下载相应的第三方类库(我这里使用的是PHPMailer)在thinkPHP中封装一下邮件服务类实际调用效果…...

Leetcode-每日一题【剑指 Offer 18. 删除链表的节点】
题目 给定单向链表的头指针和一个要删除的节点的值,定义一个函数删除该节点。 返回删除后的链表的头节点。 注意:此题对比原题有改动 示例 1: 输入: head [4,5,1,9], val 5输出: [4,1,9]解释: 给定你链表中值为 5 的第二个节点,那么在调…...

[LINUX使用] top 命令的使用
COLUMNS150 LINES100 top 序号 是否为启动命令 命令模板 详解 1 no vh 帮助 2 yes -d 0.01 0.01秒的间隔刷新top输出 3 no c COMMAND列切换 4 yes -e [k | m | g | t | p] 以何种计量单位显示内存列 k-kb,m-mb,g-gb,t-t…...

通过redis进行缓存分页,通过SCAN扫描进行缓存更新
问题:当我们要添加缓存时,如果我们用了PageHelper时,PageHelper只会对查询语句有效(使用到sql的查询),那么如果我们把查询到的数据都添加到缓存时,就会无法进行分页; 此时我们选择将…...

C#小轮子 Debug,Release,发布模式如何运行不同的代码
文章目录 前言C#运行模式运行模式介绍三种模式区分代码 前言 编译模式和发布模式的代码不一样是非常正常的。比较常见的是数据库不一样。编译测试数据库和发布真实的数据库地址不一样。 C#运行模式 运行模式介绍 运行模式有三种: Debug 不进行优化,…...

【【萌新的STM32 学习-6】】
萌新的STM32 学习-6 BSP 文件夹,用于存放正点原子提供的板级支持包驱动代码,如:LED、蜂鸣器、按键等。 本章我们暂时用不到该文件夹,不过可以先建好备用。 CMSIS 文件夹,用于存放 CMSIS 底层代码(ARM 和 ST…...

“深入解析JVM:探索Java虚拟机的工作原理“
标题:深入解析JVM:探索Java虚拟机的工作原理 摘要:本文将深入解析Java虚拟机(JVM)的工作原理,从字节码到执行过程,从内存模型到垃圾回收机制,逐步剖析JVM的核心组成部分和工作原理。…...

【目标检测系列】YOLOV2解读
为更好理解YOLOv2模型,请先移步,了解YOLOv1后才能更好的理解YOLOv2所做的改进。 前情回顾:【目标检测系列】YOLOV1解读_怀逸%的博客-CSDN博客 背景 通用的目标检测应该具备快速、准确且能过识别各种各样的目标的特点。自从引入神经网络以来&a…...

【深入浅出程序设计竞赛(基础篇)第一章 算法小白从0开始】
深入浅出程序设计竞赛(基础篇)第一章 算法小白从0开始 第一章 例题例1-1例1-2例1-3例1-4例1-5例1-6例1-7例1-8例1-9例1-10例1-11 第一章 课后习题1-11-21-31-4 第一章 例题 例1-1 #include<iostream> using namespace std;int main(){cout <&…...

openGauss学习笔记-36 openGauss 高级数据管理-TRUNCATE TABLE语句
文章目录 openGauss学习笔记-36 openGauss 高级数据管理-TRUNCATE TABLE语句36.1 语法格式36.2 参数说明36.3 示例 openGauss学习笔记-36 openGauss 高级数据管理-TRUNCATE TABLE语句 清理表数据,TRUNCATE TABLE用于删除表的数据,但不删除表结构。也可以…...

ChatGPT生成文本检测器算法挑战大赛
ChatGPT生成文本检测器算法挑战大 比赛链接:2023 iFLYTEK A.I.开发者大赛-讯飞开放平台 (xfyun.cn) 1、数据加载和预处理 import numpy as np import pandas as pd from sklearn.model_selection import train_test_split, cross_val_predict from sklearn.linea…...

O2OA开发平台实施入门指南
O2OA(翱途)开发平台,是一款适用于协同办公系统开发与实施的基础平台,说到底,它也是一款快速开发平台。开发者可以基于平台提供的能力完成门户、流程、信息相关的业务功能开发。 既然定位为开发平台,那么开…...

服装行业多模态算法个性化产品定制方案 | 京东云技术团队
一、项目背景 AI赋能服装设计师,设计好看、好穿、好卖的服装 传统服装行业痛点 • 设计师无法准确捕捉市场趋势,抓住中国潮流 • 上新周期长,高库存滞销风险大 • 基本款居多,难以满足消费者个性化需求 解决方案 • GPT数据…...

MySQL表空间结构与页、区、段的定义
文章目录 一、概念引入1、页2、区3、段 二、页的结构1、File Header2、FIle Trailer 三、区的结构1、分类2、XDES Entry3、XDES Entry链表 四、段的结构五、独立表空间1、FSP_HDR页2、XDES页3、IBUF_BITMAP页4、INODE页5、INDEX页 六、系统表空间 一、概念引入 1、页 InnoDB是…...

RaabitMQ(三) - RabbitMQ队列类型、死信消息与死信队列、懒队列、集群模式、MQ常见消息问题
RabbitMQ队列类型 Classic经典队列 这是RabbitMQ最为经典的队列类型。在单机环境中,拥有比较高的消息可靠性。 经典队列可以选择是否持久化(Durability)以及是否自动删除(Auto delete)两个属性。 Durability有两个选项,Durable和Transient。 Durable表…...

Unity3D GPU Selector/Picker
Unity3D GPU Selector/Picker 一、概述 1.动机 Unity3D中通常情况下使用物理系统进行物体点击选择的基础,对于含大量对象的场景,添加Collider组件会增加内容占用,因此使用基于GPU的点击选择方案 2.实现思路 对于场景的每个物体,…...

灰度非线性变换之c++实现(qt + 不调包)
本章介绍灰度非线性变换,具体内容包括:对数变换、幂次变换、指数变换。他们的共同特点是使用非线性变换关系式进行图像变换。 1.灰度对数变换 变换公式:y a log(1x) / b,其中,a控制曲线的垂直移量;b为正…...

轻量级Web框架Flask
Flask-SQLAlchemy MySQL是免费开源软件,大家可以自行搜索其官网(https://www.MySQL.com/downloads/) 测试MySQL是否安装成功 在所有程序中,找到MySQL→MySQL Server 5.6下面的命令行工具,然后单击输入密码后回车&am…...

【gridsample】地平线如何支持gridsample算子
文章目录 1. grid_sample算子功能解析1.1 理论介绍1.2 代码分析1.2.1 x,y取值范围[-1,1]1.2.2 x,y取值范围超出[-1,1] 2. 使用grid_sample算子构建一个网络3. 走PTQ进行模型转换与编译 实操以J5 OE1.1.60对应的docker为例 1. grid_sample算子功能解析 该段主要参考:…...

JPA实现存储实体类型信息
本文已收录于专栏 《Java》 目录 背景介绍概念说明DiscriminatorValue 注解:DiscriminatorColumn 注解:Inheritance(strategy InheritanceType.SINGLE_TABLE) 注解: 实现方式父类子类执行效果 总结提升 背景介绍 在我们项目开发的过程中经常…...

阿里云快速部署开发环境 (Apache + Mysql8.0+Redis7.0.x)
本文章的内容截取于云服务器管理控制台提供的安装步骤,再整合前人思路而成,文章末端会提供原文连接 ApacheMysql 8.0部署MySQL数据库(Linux)步骤一:安装MySQL步骤二:配置MySQL步骤三:远程访问My…...

语音秘书:让录音转文字识别软件成为你的智能工作助手
每当在需要写文章的深夜,我的思绪经常跟不上我的笔,即便是说出来用录音机录下,再书写出来,也需要耗费大量时间。这个困扰了我很久的问题终于有了解决的办法,那就是录音转文字软件。它像个语言魔术师,将我所…...

【腾讯云 Cloud Studio 实战训练营】用于编写、运行和调试代码的云 IDE泰裤辣
文章目录 一、引言✉️二、什么是腾讯云 Cloud Studio🔍三、Cloud Studio优点和功能🌈四、Cloud Studio初体验(注册篇)🎆五、Cloud Studio实战演练(实战篇)🔬1. 初始化工作空间2. 安…...

[C#] 简单的俄罗斯方块实现
一个控制台俄罗斯方块游戏的简单实现. 已在 github.com/SlimeNull/Tetris 开源. 思路 很简单, 一个二维数组存储当前游戏的方块地图, 用 bool 即可, true 表示当前块被填充, false 表示没有. 然后, 抽一个 “形状” 类, 形状表示当前玩家正在操作的一个形状, 例如方块, 直线…...

postman官网下载安装登录详细教程
目录 一、介绍 二、官网下载 三、安装 四、注册登录postman账号(不注册也可以) postman注册登录和不注册登录的使用区别 五、关于汉化的说明 一、介绍 简单来说:是一款前后端都用来测试接口的工具。 展开来说:Postman 是一个…...

(贪心) 剑指 Offer 14- I. 剪绳子 ——【Leetcode每日一题】
❓剑指 Offer 14- I. 剪绳子 难度:中等 给你一根长度为 n 的绳子,请把绳子剪成整数长度的 m 段(m、n都是整数,n > 1 并且 m > 1),每段绳子的长度记为 k[0],k[1]...k[m-1] 。请问 k[0]*k[1]*...*k[m…...

如何将Linux上的cpolar内网穿透设置成 - > 开机自启动
如何将Linux上的cpolar内网穿透设置成 - > 开机自启动 文章目录 如何将Linux上的cpolar内网穿透设置成 - > 开机自启动前言一、进入命令行模式二、输入token码三、输入内网穿透命令 前言 我们将cpolar安装到了Ubuntu系统上,并通过web-UI界面对cpolar的功能有…...

50.两数之和(力扣)
目录 问题描述 核心代码解决 代码思想 时间复杂度和空间复杂度 问题描述 给定一个整数数组 和一个整数目标值 ,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。numstarget 你可以假设每种输入只会对应一个答案。但是&am…...