#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qevent.h"
#include <Windows.h>
#include <WindowsX.h>
#define WINDOW_FRAME_BORDER 4
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setMouseTracking(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
return winEvent( (MSG*)message,result );
}
bool MainWindow::winEvent(MSG *message, long *result)
{
switch(message->message)
{
case WM_NCHITTEST:
int xPos = GET_X_LPARAM(message->lParam) - this->frameGeometry().x();
int yPos = GET_Y_LPARAM(message->lParam) - this->frameGeometry().y();
int nLeft = 0;
int nTop = 0;
int nRight = width();
int nBottom = height();
long flag = 0;
if (topHeight + WINDOW_FRAME_BORDER > qAbs(nTop - yPos) &&
qAbs(nTop - yPos) > WINDOW_FRAME_BORDER)
{
*result = HTCAPTION;
return true;
}
if( WINDOW_FRAME_BORDER > qAbs( nLeft - xPos ) )
{
flag = HTLEFT;
*result = HTLEFT;
}
if( WINDOW_FRAME_BORDER > qAbs( nRight - xPos ) )
{
flag = HTRIGHT;
*result = HTRIGHT;
}
if( WINDOW_FRAME_BORDER > qAbs( nTop - yPos ) )
{
if (flag == HTLEFT)
{
*result = HTTOPLEFT;
}
else if(flag == HTRIGHT)
{
*result = HTTOPRIGHT;
}
else
{
flag = HTTOP;
*result = HTTOP;
}
}
if( WINDOW_FRAME_BORDER > qAbs( nBottom - yPos ) )
{
if (flag == HTLEFT)
{
*result = HTBOTTOMLEFT;
}
else if (flag == HTRIGHT)
{
*result = HTBOTTOMRIGHT;
}
else
{
flag = HTBOTTOM;
*result = HTBOTTOM;
}
}
if (flag == 0)
{
return false;
}
return true;
}
return false;
}
没有合适的资源?快使用搜索试试~ 我知道了~
QMainWindow无标题栏和边框依然可以通过四周改变窗口大小
共14个文件
user:2个
log:2个
cpp:2个
1星 需积分: 48 62 下载量 172 浏览量
2019-03-16
15:28:23
上传
评论 2
收藏 17.47MB ZIP 举报
温馨提示
QMainWindow通过setWindowFlags(Qt::FramelessWindowHint)该函数隐藏掉标题栏以后,就不能通过窗口四周来拖动大小了,所以必须要重写,重写两种方法:第一种重写是:mouseMoveEvent,该方法要设置以下两点(1)setMouseTracking(true); //开启鼠标追踪 (2)ui.centralWidget->setLayout(ui.mainLayout);因为我的界面是new出来的,没有具体的ui界面所以用的是第二种通过nativeEvent()和winEvent()函数实现的,具体实现过程看代码
资源推荐
资源详情
资源评论
收起资源包目录
QMainWindow.zip (14个子文件)
QMainWindow
test2
DTAR_08E86330_4835_4B5C_9E5A_61F37AE1A077_DTAR
test2.VC.db 47.94MB
test2.pro.user 23KB
test2.vcxproj.user 603B
obj
Debug
mainwindow.cpp 2KB
debug
.vs
test2
v14
.suo 38KB
GeneratedFiles
Debug
test2.vcxproj 13KB
mainwindow.h 499B
test2.vcxproj.filters 3KB
Win32
Debug
test2.Build.CppClean.log 841B
test2.log 3B
test2.tlog
test2.pro 378B
main.cpp 332B
test2.sln 937B
mainwindow.ui 1KB
共 14 条
- 1
资源评论
- 小智科技2022-05-05可以编译,移动不了。
weixin_42051266
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功