|
winEvent该方法在qt5中已删除。对于你的问题可以这么写,其中定义的宏只是大概定义了一个检测误差
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.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);
setWindowFlags(Qt::FramelessWindowHint);
}
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();
if(this->childAt(xPos,yPos) == 0)
{
*result = HTCAPTION;
}else{
//return false;
}
int nLeft = 0;
int nTop = 0;
int nRight = width();
int nBottom = height();
bool bAdditional = false;
if( WINDOW_FRAME_BORDER > qAbs( nLeft - xPos ) )
{
bAdditional = true;
*result = HTLEFT;
}
if( WINDOW_FRAME_BORDER > qAbs( nRight - xPos ) )
{
bAdditional = true;
*result = HTRIGHT;
}
if( WINDOW_FRAME_BORDER > qAbs( nTop - yPos ) )
{
if( bAdditional )
{
*result = HTTOPRIGHT;
}
else
{
*result = HTTOP;
}
}
if( WINDOW_FRAME_BORDER > qAbs( nBottom - yPos ) )
{
if( bAdditional )
{
*result = HTBOTTOMRIGHT;
}
else
{
*result = HTBOTTOM;
}
}
return true;
}
return false;
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
protected:
bool winEvent(MSG *message, long *result);
bool nativeEvent(const QByteArray & eventType, void * message, long * result);
};
#endif // MAINWINDOW_H
|
|