Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. 【已解决】Qt无边框MainWindow如何拖动四周改变大小?
Forum Updated to NodeBB v4.3 + New Features

【已解决】Qt无边框MainWindow如何拖动四周改变大小?

Scheduled Pinned Locked Moved Chinese
5 Posts 3 Posters 13.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saki
    wrote on last edited by
    #1

    我做了一个FrameLess的MainWindow,只是想做个类似于Photoshop那样的窗体,但是现在我无法像正常的窗口一样改变大小。只有一个状态栏右下角的那个东西能改变大小。

    我想要做成和正常窗体一样。四角都能改变大小 ,四边也能拖动改变大小的窗体,我试过使用CustomizeWindowHint,但是在我的Ubuntu上没有任何效果。究其原因应该是X11的问题。求教各位大侠我应该怎么办?

    (我用MousePress之类的事件写了一个很简陋的改变,但是漏洞太多了……)
    ——————————————————————
    解决方法:
    参照以前版本的Qt中一个DragProxy仿写一个即可。

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jiangcaiyang
      wrote on last edited by
      #2

      想知道LZ究竟是用什么方法制作一个自定义样式的窗口?
      是用QSS实现的吗?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Saki
        wrote on last edited by
        #3

        [quote author="jiangcaiyang" date="1373809087"]想知道LZ究竟是用什么方法制作一个自定义样式的窗口?
        是用QSS实现的吗?[/quote]

        抱歉,我是用一个FramelessWindowHint和一个自己写的Style来实现的。就是因为用了FrameLessWindowHint结果才出现的各种问题,移动和最大最小化的问题都已经解决了。现在就是差一个大小调整的东西了。记得原来还有个很方便的调整大小的Frame还是什么直接设一个就可以了。Qt5里面好像把这个给删去了。

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Saki
          wrote on last edited by
          #4

          [quote author="jiangcaiyang" date="1373809087"]想知道LZ究竟是用什么方法制作一个自定义样式的窗口?
          是用QSS实现的吗?[/quote]

          您知道怎么实现这个效果么?感激不尽啊QAQ

          1 Reply Last reply
          0
          • T Offline
            T Offline
            TDHound
            wrote on last edited by
            #5

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

            }
            @

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved