#include "movewidget.h"
#include "movewidget.h"
#include <QMouseEvent>
#include <QStyleOption>
#include <QPainter>
#include <QHBoxLayout>
#include <QDebug>
movewidget::movewidget(QWidget *parent) : QWidget(parent)
{
setWindowFlags(Qt::FramelessWindowHint);
border_px = 4;
posBy = pos_none;
setMouseTracking(true);
}
void movewidget::mousePressEvent(QMouseEvent *event)
{
event->ignore();
if (event->button() == Qt::LeftButton)
{
win_pos = event->globalPos() - frameGeometry().topLeft();
}
}
void movewidget::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton){
if(posBy == pos_none){
move(event->globalPos() - win_pos);
}
else{
int m_top,m_bottom,m_left,pright;
m_top = frameGeometry().top();
m_bottom =frameGeometry().bottom();
m_left = frameGeometry().left();
pright = frameGeometry().right();
if(posBy & top){
if(height() == minimumHeight()){
m_top = qMin(event->y()+this->pos().y(),m_top);
}
else if(height() == maximumHeight()){
m_top = qMax(event->y()+this->pos().y(),m_top);
}
else{
m_top = event->y()+this->pos().y();
}
}
else if(posBy & bottom){
if(height() == minimumHeight()){
m_bottom = qMax(event->y()+this->pos().y(),m_top);
}
else if(height() == maximumHeight()){
m_bottom = qMin(event->y()+this->pos().y(),m_top);
}
else{
m_bottom = event->y()+this->pos().y();
}
}
if(posBy & left){
if(width() == minimumWidth()){
m_left = qMin(event->x()+this->pos().x(),m_left);
}
else if(width() == maximumWidth()){
m_left = qMax(event->x()+this->pos().x(),m_left);
}
else{
m_left = event->x()+this->pos().x();
}
}
else if(posBy & right){
if(width() == minimumWidth()){
pright = qMax(event->x()+this->pos().x(),pright);
}
else if(width() == maximumWidth()){
pright = qMin(event->x()+this->pos().x(),pright);
}
else{
pright =event->x()+this->pos().x();
}
}
setGeometry(QRect(QPoint(m_left,m_top),QPoint(pright,m_bottom)));
}
}
else arrows_update();
}
void movewidget::arrows_update()
{
int diffLeft = abs(mapFromGlobal(cursor().pos()).x() -frameGeometry().left()+this->pos().x());
int diffRight = abs(mapFromGlobal(cursor().pos()).x() -frameGeometry().right()+this->pos().x());
int diffTop = abs(mapFromGlobal(cursor().pos()).y() - frameGeometry().top()+this->pos().y());
int diffBottom = abs(mapFromGlobal(cursor().pos()).y() - frameGeometry().bottom()+this->pos().y());
QCursor my_cursor;
my_cursor = cursor();
if(diffTop < border_px){
if(diffLeft < border_px){
posBy = top_Left;
my_cursor.setShape(Qt::SizeFDiagCursor);
}
else if(diffRight < border_px){
posBy = topRight;
my_cursor.setShape(Qt::SizeBDiagCursor);
}
else{
posBy = top;
my_cursor.setShape(Qt::SizeVerCursor);
}
}
else if(diffBottom < border_px){
if(diffLeft < border_px){
posBy = bottomLeft;
my_cursor.setShape(Qt::SizeBDiagCursor);
}
else if(diffRight < border_px){
posBy = bottomRight;
my_cursor.setShape(Qt::SizeFDiagCursor);
}
else{
posBy = bottom;
my_cursor.setShape(Qt::SizeVerCursor);
}
}
else if(diffLeft < border_px){
posBy = left;
my_cursor.setShape(Qt::SizeHorCursor);
}
else if(diffRight < border_px){
posBy = right;
my_cursor.setShape(Qt::SizeHorCursor);
}
else{
posBy = pos_none;
my_cursor.setShape(Qt::ArrowCursor);
}
setCursor(my_cursor);
}
void movewidget::mouseReleaseEvent(QMouseEvent *event)
{
event->ignore();
if(posBy != pos_none){
arrows_update();
}
}
Qt 5.11 无边框可拖动 可改变大小窗口
需积分: 50 22 浏览量
2018-11-19
13:51:50
上传
评论 2
收藏 4KB 7Z 举报
qq_33702791
- 粉丝: 1
- 资源: 2
最新资源
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
- 音乐展示网页、基于Stenography的图像数字水印添加与提取,以及基于颜色矩和Tamura算法的图像相似度评估算法py源码
- 基于EmguCV(OpenCV .net封装),图像数字水印加解密算法的实现,其中包含最低有效位算法,离散傅里叶变换算法+文档书
- 基于matlab+DWT的图像水印项目,数字水印+源代码+文档说明+图片+报告pdf
- (优秀毕业设计)基于python实现的数字图像可视化水印系统的设计与实现,多种数字算法实现+源代码+文档说明+理论演示pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈