QT笔记之不规则窗口的实现
QT实现的不规则窗口,是根据图片的形状显示
1.去标题栏
2.设置窗口背景为透明色
3.最后给窗口设置背景色
注:背景图为镂空的 格式为.png
图片资源下载:http://pan.baidu.com/s/1i5JkIot
.h
#ifndef QANORMALYDLG_H
#define QANORMALYDLG_H #include <QWidget>
#include "ui_qanormalydlg.h" class QAnormalyDlg : public QWidget
{
Q_OBJECT public:
QAnormalyDlg(QWidget *parent = );
~QAnormalyDlg(); void paintEvent(QPaintEvent *e); void mousePressEvent(QMouseEvent *e); void mouseMoveEvent(QMouseEvent *e);
private:
Ui::QAnormalyDlg ui; QPoint move_point; //移动的距离
}; #endif // QANORMALYDLG_H
.cpp
#include "qanormalydlg.h"
#include <QPainter>
#include <QMouseEvent> QAnormalyDlg::QAnormalyDlg(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this); //去表框 同时保留窗口原有的属性
setWindowFlags(Qt::FramelessWindowHint | windowFlags() );
//把窗口背景设为透明
setAttribute(Qt::WA_TranslucentBackground);
resize(,);
} QAnormalyDlg::~QAnormalyDlg()
{ } void QAnormalyDlg::paintEvent(QPaintEvent *e)
{
QPainter p(this);
p.drawPixmap(, , QPixmap("122.png"));
} void QAnormalyDlg::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::RightButton)
{
//右键关闭窗口
close();
} else if (e->button() == Qt::LeftButton)
{
//求坐标差,当前鼠标坐标 - 窗口左上角坐标
//frameGeometry返回窗口的矩形坐标, topLeft返回窗口左上角点的坐标
//move_point = e->globalPos() - this->frameGeometry().topLeft();
move_point = e->globalPos() - this->pos();
}
} void QAnormalyDlg::mouseMoveEvent(QMouseEvent *e)
{
if (e->buttons() & Qt::LeftButton)
{
move(e->globalPos()-move_point);
}
}
效果:

QT笔记之不规则窗口的实现的更多相关文章
- QT笔记之自定义窗口拖拽移动
1.QT自定义标题栏,拖拽标题栏移动窗口(只能拖拽标题,其他位置无法拖拽) 方法一: 转载:http://blog.sina.com.cn/s/blog_4ba5b45e0102e83h.html . ...
- QT:不规则窗口的实现
主要思路:1:将窗体设为Qt::FramelessWindowHint(去掉标题栏).2:用一幅有部分区域是透明的图片作为程序的界面,并将图片透明的地方设为穿透. 3:重载程序的鼠标事件. 运行时截图 ...
- QT笔记之实现阴影窗口
方法一: 代码实现 在窗口构造函数中加入:setAttribute(Qt::WA_TranslucentBackground),保证不被绘制上的部分透明 重写void paintEvent(QPain ...
- QT笔记之VS2010 Qt中导入qrc资源文件
转载1:http://qimo601.iteye.com/blog/1404693 转载2:http://blog.sina.com.cn/s/blog_92cde3060101lobm.html 转 ...
- Windows SDK 实现不规则窗口介绍
不规则窗口在程序界面设计中能提供非常好的用户体验,以下是我程序运行时的效果图: 以下是代码,注意需要修改一些简单的位置,如资源ID,项目的头文件等,这些是根据你创建的win32程序的项目名改变的,我的 ...
- Qt全屏显示窗口、子窗口的相关函数
Qt全屏显示函数 window.showFullScreen() Qt最大化显示函数 window.showMaximized() Qt最小化显示函数 ...
- Qt控制台和带窗口的区别_mickelfeng_新浪博客
Qt控制台和带窗口的区别_mickelfeng_新浪博客 t控制台和带窗口的区别 (2012-04-30 10:50:53) 标签: 杂谈 分类: C/C ...
- Qt创建停靠悬浮窗口
1.Qt实现窗口停靠和悬浮使用类QDockWidget,它有两个重要方法用来设置停靠特性以及停靠区域, dw1->setFeatures(QDockWidget::DockWidgetMovab ...
- 3dsmax不同版本 pyside qt UI 设置max窗口为父窗口的方法
3dsmax不同版本 pyside qt widget 设置 max 窗口为父窗口的方法 前言: 3dsmax 在 2014 extension 之后开始集成 Python 和 PySide,但是在版 ...
随机推荐
- iOS Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:7962
Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Cac ...
- jquery_DOM操作
DOM操作:DOM Core(核心),HTML_DOM,CSS_DOM CSS_DOM操作: css()获取或添加样式 opacity()透明设置 height()高度值 width()宽度 offs ...
- github标记
<template> <a href="https://github.com/lmk123/Runner" class="github-corner&q ...
- angularJs模糊查询
html代码 <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <tit ...
- Nginx + php-fpm 执行 PHP 脚本超时 报错 502 Bad Gateway + 504 Gateway Time-out 的解决办法
上周写好的发送邮件的计划任务只发送了一部分,检查计划任务日志,发现 502 Bad Gateway 的错误(已经在脚本中设置了 set_time_limit(0)). 后来在网上查找资料,可以通过以下 ...
- Example Microprocessor Register Organizations
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION
- js滚动加载插件
function $xhyload(o){ var that=this; if(!o){ return; }else{ that.win=$(o.config.obj); that.qpanel=$( ...
- C#中的泛型 【转】
C#中的泛型 泛型(generic)是C#语言2.0和通用语言运行时(CLR)的一个新特性.泛型为.NET框架引入了类型参数(type parameters)的概念.类型参数使得设计类和方法时,不必确 ...
- git cherry-pick. 如何把已经提交的commit, 从一个分支放到另一个分支
问题 在本地master提交了一个commit(8d85d4bca680a5dbcc3e5cfb3096d18cd510cc9f),如何提交的test_2分之上? 方法 使用cherry-pick 用 ...
- Java基础之在窗口中绘图——绘制星星(StarApplet 1)
Applet程序. 可以把更复杂的几何形状定义为GeneralPath类型的对象.GeneralPath可以是直线.Quad2D曲线和Cubic2D曲线的结合体,甚至可以包含其他GeneralPath ...