zoukankan      html  css  js  c++  java
  • Qt无边框MainWindow如何拖动四周改变大小

    原来还有winEvent(), x11Event() and macEvent() 这些东西。。。不过貌似还需要找更好的办法,否则就无法跨平台了。

    你需要重新处理部分窗体事件,以下代码适用于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

  • 相关阅读:
    Redis单点登录
    MySQL有哪些存储引擎,各自的优缺点,应用场景
    MySQL慢查询优化、索引优化、以及表等优化总结
    Redis缓存和MySQL数据一致性方案详解
    Jenkies+github实现代码自动构建
    Python基础-day14-单元测试注册小例子
    Python基础-day13-unitest框架(Suite、runner)及生成报告,附带最新的HTMLTestRunnerNew.py文件
    Python基础-day11-继承和动态设置属性
    Python基础-day10-类的创建和调用
    Python基础-day03 字符串
  • 原文地址:https://www.cnblogs.com/findumars/p/4700007.html
Copyright © 2011-2022 走看看