#include "widget.h"
#include <QMouseEvent>
#include <qt_windows.h>
#include <windowsx.h>
#include <Windows.h>
#define BORDER_WIDTH 5
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint);
setAttribute(Qt::WA_Hover);
}
Widget::~Widget()
{
}
bool Widget::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
MSG* param = static_cast<MSG*>(message);
switch (param->message)
{
case WM_NCHITTEST:
{
int nX = GET_X_LPARAM(param->lParam) - this->geometry().x();
int nY = GET_Y_LPARAM(param->lParam) - this->geometry().y();
if(childAt(nX, nY) != nullptr)
return QWidget::nativeEvent(eventType, message, result);
if((nX > 0) && (nX < BORDER_WIDTH))
*result = HTLEFT;
if((nX > this->width() - BORDER_WIDTH) && (nX < this->width()))
*result = HTRIGHT;
if((nY > 0) && (nY < BORDER_WIDTH))
*result = HTTOP;
if((nY > this->height() - BORDER_WIDTH) && (nY < this->height()))
*result = HTBOTTOM;
if((nX > 0) && (nX < BORDER_WIDTH) && (nY > 0) && (nY < BORDER_WIDTH))
*result = HTTOPLEFT;
if((nX > this->width() - BORDER_WIDTH) && (nX < this->width()) &&
(nY > 0) && (nY < BORDER_WIDTH))
*result = HTTOPRIGHT;
if((nX > 0) && (nX < BORDER_WIDTH) && (nY > this->height() - BORDER_WIDTH)
&& (nY < this->height()))
*result = HTBOTTOMLEFT;
if((nX > this->width() - BORDER_WIDTH) && (nX < this->width())
&& (nY > this->height() - BORDER_WIDTH) && (nY < this->height()))
*result = HTBOTTOMRIGHT;
return true;
}
}
return false;
}
Qt实现手动拉伸窗口大小代码(nativeEvent)
最新推荐文章于 2024-05-23 23:26:08 发布