qt 界面去掉系统边框

摘要:
实现了拖放功能和关闭功能。如果你需要放大或缩小,你需要自己做。
该代码在Qt5框架编辑,使用该类时, 直接继承这个类就可以了。 实现了拖拽功能和关闭功能,如果需要放大缩小功能, 需自己实现。

1
#ifndef CUSTOMIZE_QWIDGET_H 2 #define CUSTOMIZE_QWIDGET_H 3 #include <QWidget> 4 #include <QMouseEvent> 5 6 class CustomizeQWidget : public QWidget 7 { 8 Q_OBJECT 9 public: 10 explicit CustomizeQWidget(QWidget *parent = 0); 11 ~CustomizeQWidget(); 12 public slots: 13 void on_button_close_clicked(); 14 private: 15 void paintEvent(QPaintEvent *); 16 void mousePressEvent(QMouseEvent *event); 17 void mouseMoveEvent(QMouseEvent *event); 18 private: 19 QPoint m_last_mouse_position; 20 }; 21 #endif // CUSTOMIZE_QWIDGET_H
 1 #include "customize_qwidget.h"
 2 #include <QStyleOption>
 3 #include <QPainter>
 4 #include <QBrush>
 5 
 6 CustomizeQWidget::CustomizeQWidget(QWidget *parent)
 7     : QWidget(parent)
 8 {
 9     this -> setWindowFlags(Qt::FramelessWindowHint);
10 }
11 
12 CustomizeQWidget::~CustomizeQWidget()
13 {
14 }
15 
16 void CustomizeQWidget::paintEvent(QPaintEvent *)
17 {
18     QStyleOption opt;
19     opt.init(this);
20     QPainter p(this);
21     style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
22 }
23 
24 void CustomizeQWidget::mousePressEvent(QMouseEvent *event)
25 {
26     if(event->button() == Qt::LeftButton)
27     {
28         m_last_mouse_position = event->globalPos();
29     }
30 }
31 
32 void CustomizeQWidget::mouseMoveEvent(QMouseEvent *event)
33 {
34     if (!event->buttons().testFlag(Qt::LeftButton))
35             return;
36     const QPoint position = pos() + event->globalPos() - m_last_mouse_position; //the position of mainfrmae + (current_mouse_position - last_mouse_position)
37     move(position.x(), position.y());
38     m_last_mouse_position = event->globalPos();
39 }
40 
41 void CustomizeQWidget::on_button_close_clicked()
42 {
43     this->close();
44 }

免责声明:文章转载自《qt 界面去掉系统边框》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇解决Sublime text 3 中文文件名显示方框Java 的类加载顺序下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Web前端-按钮点击效果(水波纹)

这种效果可以由元素内嵌套canves实现,也可以由css3实现。 Canves实现 网上摘了一份canves实现的代码,略微去掉了些重复定义的样式并且给出js注释,代码如下 第一种方法: html骨架代码 <a class="btn color-1 material-design"data-color="#2f5398">Press me!&...

如何实现在H5里调起高德地图APP?

http://www.cnblogs.com/milkmap/p/5912350.html 这一篇文章,将讲述如何在H5里调起高德地图APP,并展示兴趣点。适合于展示某个餐馆,商场等,让用户自行选择前往方式。 场景一、在高德地图上展示Marker点或者POI标记 在一些基于位置分享的应用开发中,我们会在地图上标记marker点或者使用地图上的poi点,这时...

python_14(js)

第1章 图片方法 1.1 设置背景图:1.2 背景图问题:1.3 background-repeat; noa-repe 1.4 background-attachment: fixed1.5 background-position 1.6 background-position-x 1.7 截取局部1.7.1 透明色第2章 定位 2.1 定义形式2.2...

爬虫:滑动验证解决方法及python实现

爬虫时遇到滑动验证,基本思路是通过selenium操作浏览器,将滑动验证的原始图片和缺口图片进行对比,找出缺口位置,然后在利用selenium模拟拖动滑块,达到验证的目的。下面就以猪八戒网为例,进行操作。 一、分析 首先访问 https://account.zbj.com/login: 登陆页面主要为上图。 点击按钮(div标签,类名为 geetest_...

Android源码分析(一)-----如何快速掌握Android编译文件

一 : Android.mk文件概述 主要向编译系统指定相应的编译规则。会被解析一次或多次。因此尽量减少源码中声明变量,因为这些变量可能会被多次定义从而影响到后面的解析。这个文件的语法会把源代码组织成模块,每个模块属于下列类型之一: - APK程序:一般的Android程序,编译打包生成apk文件。 - JAVA库:java类库,编译打包生成jar包文件。...

vs2010驱动开发环境配置

1、文件 -> 新建 -> 项目 -> Visual C++ -> 空项目 名称:Driver 2、生成 -> 配置管理器   活动解决方案配置: 新建 名称:Driver Debug 从此处复制设置:Debug 3、视图 -> 属性管理器  展开刚配置的Driver Debug | Win32  ->  右...