来源:Qt项目中的常见用法
setWindowFlags(Qt::FramelessWindowHint);
- 无title窗口拉伸(windows环境)
- bool MyWindow::nativeEvent(const QByteArray & eventType, void * message, long * result)
- {
- Q_UNUSED(eventType);
- if (this->isMaximized()) {
- return false;
- }
- const int HIT_BORDER = 5;
- const MSG *msg=static_cast<MSG*>(message);
- if(msg->message == WM_NCHITTEST) {
- int xPos = ((int)(short)LOWORD(msg->lParam)) - this->frameGeometry().x();
- int yPos = ((int)(short)HIWORD(msg->lParam)) - this->frameGeometry().y();
- if(this->childAt(xPos,yPos) == 0) {
- *result = HTCAPTION;
- } else {
- return false;
- }
- if(xPos > 0 && xPos < HIT_BORDER) {
- *result = HTLEFT;
- }
- if(xPos > (this->width() - HIT_BORDER) && xPos < (this->width() - 0)) {
- *result = HTRIGHT;
- }
- if(yPos > 0 && yPos < HIT_BORDER) {
- *result = HTTOP;
- }
- if(yPos > (this->height() - HIT_BORDER) && yPos < (this->height() - 0)) {
- *result = HTBOTTOM;
- }
- if(xPos > 0 && xPos < HIT_BORDER && yPos > 0 && yPos < HIT_BORDER) {
- *result = HTTOPLEFT;
- }
- if(xPos > (this->width() - HIT_BORDER) && xPos < (this->width() - 0) && yPos > 0 && yPos < HIT_BORDER) {
- *result = HTTOPRIGHT;
- }
- if(xPos > 0 && xPos < HIT_BORDER && yPos > (this->height() - HIT_BORDER) && yPos < (this->height() - 0)) {
- *result = HTBOTTOMLEFT;
- }
- if(xPos > (this->width() - HIT_BORDER) && xPos < (this->width() - 0) && yPos > (this->height() - HIT_BORDER) && yPos < (this->height() - 0)) {
- *result = HTBOTTOMRIGHT;
- }
- return true;
- }
- return false;
- }