Qt无边框MainWindow如何拖动四周改变大小
2015-08-03 18:07
706 查看
原来还有winEvent(), x11Event() and macEvent() 这些东西。。。不过貌似还需要找更好的办法,否则就无法跨平台了。
你需要重新处理部分窗体事件,以下代码适用于Windows平台,仅供参考!
参考:https://forum.qt.io/topic/29398/%E5%B7%B2%E8%A7%A3%E5%86%B3-qt%E6%97%A0%E8%BE%B9%E6%A1%86mainwindow%E5%A6%82%E4%BD%95%E6%8B%96%E5%8A%A8%E5%9B%9B%E5%91%A8%E6%94%B9%E5%8F%98%E5%A4%A7%E5%B0%8F/5
http://blog.csdn.net/kfbyj/article/details/9284923
你需要重新处理部分窗体事件,以下代码适用于Windows平台,仅供参考!
bool MainWindow::winEvent(MSG *msg, long *result) { switch (msg->message) { case WM_NCHITTEST: { *result = 0; const LONG border_width = 8; //in pixels RECT winrect; GetWindowRect(winId(), &winrect); long x = GET_X_LPARAM(msg->lParam); long y = GET_Y_LPARAM(msg->lParam); bool resizeWidth = minimumWidth() != maximumWidth(); bool resizeHeight = minimumHeight() != maximumHeight(); if(resizeWidth) { //left border if (x >= winrect.left && x < winrect.left + border_width) { *result = HTLEFT; } //right border if (x < winrect.right && x >= winrect.right - border_width) { *result = HTRIGHT; } } if(resizeHeight) { //bottom border if (y < winrect.bottom && y >= winrect.bottom - border_width) { *result = HTBOTTOM; } //top border if (y >= winrect.top && y < winrect.top + border_width) { *result = HTTOP; } } if(resizeWidth && resizeHeight) { //bottom left corner if (x >= winrect.left && x < winrect.left + border_width && y < winrect.bottom && y >= winrect.bottom - border_width) { *result = HTBOTTOMLEFT; } //bottom right corner if (x < winrect.right && x >= winrect.right - border_width && y < winrect.bottom && y >= winrect.bottom - border_width) { *result = HTBOTTOMRIGHT; } //top left corner if (x >= winrect.left && x < winrect.left + border_width && y >= winrect.top && y < winrect.top + border_width) { *result = HTTOPLEFT; } //top right corner if (x < winrect.right && x >= winrect.right - border_width && y >= winrect.top && y < winrect.top + border_width) { *result = HTTOPRIGHT; } } if(*result == 0) return QWidget::winEvent(msg,result); return true; break; } //end case WM_NCHITTEST default: return QWidget::winEvent(msg,result); } }
参考:https://forum.qt.io/topic/29398/%E5%B7%B2%E8%A7%A3%E5%86%B3-qt%E6%97%A0%E8%BE%B9%E6%A1%86mainwindow%E5%A6%82%E4%BD%95%E6%8B%96%E5%8A%A8%E5%9B%9B%E5%91%A8%E6%94%B9%E5%8F%98%E5%A4%A7%E5%B0%8F/5
http://blog.csdn.net/kfbyj/article/details/9284923
相关文章推荐
- QTableView实时更新数据
- VS2008+Qt4.7.3+VTK5.10.1+PCL1.5.1
- Qt容器类整理
- Qt Creator 要掌握的快捷操作
- 利用QT来实现基本图形的绘制应用
- QT编程中编译的时候出现c_jkdacx0.obj : error LNK2001: 无法解析的外部符号 "class QTextCodec * GlobalCodec" ?
- Qtcreator 环境使用
- 《转》qt中添加背景图片(stylesheet)
- Qt中的二维图形(二)
- QT 中文转拼音
- Qt的二维图形
- 【Qt OpenGL教程】09:在3D空间中移动位图
- UBuntu14.04下安装和卸载Qt5.3.1
- Qt5.5 连接Access2007数据库
- QT中编译时出现main.cpp: No such file or directory
- QtSQL SERVER连接数据库
- Qt中在槽函数中获取QListWidget中的各个部件
- Qt 5.3 下OpenCV 2.4.11 开发(8)查表法直方图修改图像
- QT快捷键
- 【Qt OpenGL教程】08:混合