• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會(huì)很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::

            From: http://blog.csdn.net/kfbyj/article/details/9284923


            最近做項(xiàng)目遇到的問題,總結(jié)下。

            有時(shí)候我們覺得系統(tǒng)的標(biāo)題欄和按鈕太丑太呆板,想做自己的標(biāo)題欄以及最大化、最小化、關(guān)閉,菜單按鈕,我們就需要 

            1. setWindowFlags(Qt::FramelessWindowHint);  
            但是這樣過后,我們就不能拖動(dòng)窗口改變位置,以及拖動(dòng)邊緣改變窗口大小了。

            有兩種方案處理這種情況:

            1.自己對(duì)mouseMoveEvent,mousePressEvent,mouseReleaseEvent 等事件進(jìn)行處理。

            2.Qt可以處理windows的消息。大家重新實(shí)現(xiàn)bool winEvent(MSG *message, long *result);(在此又一次感覺Qt的NB)


            我剛開始使用第一種方法去實(shí)現(xiàn)的。移動(dòng)窗口很容易做,大家可以去看看這個(gè)大大寫的,比網(wǎng)上其他版本問題少些。

            http://blog.csdn.net/aqtata/article/details/8902889

            在窗口邊緣按下鼠標(biāo)拖動(dòng)改變窗口大小就比較麻煩了。

            我是這樣做的:

            在mousePressEvent 按下設(shè)置m_bPressed為真。

            在mouseMoveEvent中m_bPressed為真且event->x() 在窗口邊緣 及處理算出鼠標(biāo)移動(dòng)的增量 然后不斷resize窗口。

            至于如何為邊緣的斷定,就自己設(shè)定一個(gè) 差值 假如 在窗口邊緣 ±4個(gè)px 就算在在該邊緣就處理該resize。

            這樣做缺點(diǎn)很多,1.拖快了不行,很容易超過該差值 , 2.窗口抖動(dòng)的厲害,一直在resize,3.要處理太多情況


            鑒于上訴缺點(diǎn)于是乎就到處問人百度google。有了第二種方法:

            第二種方法很好用,效果和有標(biāo)題邊框程序一樣~~~

            Qt居然可以處理windows消息。。

            這里我們要重新實(shí)現(xiàn)winEvent ( MSG * message, long * result ) 

            該虛函數(shù)在QWidget和QWizard以及QSizeGrip以及他們的子類中都可以實(shí)現(xiàn)。

            如果你想停止Qt處理消息就返回true,并且設(shè)置result到你想要保存的值返回給window處理。否者的話返回false。

            這里我們主要想處理WM_NCHITTEST消息。

            The WM_NCHITTEST message is sent to a window in order to determine what part of the window corresponds to a particular screen coordinate. This can happen, for example, when the cursor moves, when a mouse button is pressed or released, or in response to a call to a function such as WindowFromPoint. If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent to the window that has captured the mouse.

            A window receives this message through its WindowProc function. 

            WM_NCHITTEST的消息響應(yīng)函數(shù)會(huì)根據(jù)鼠標(biāo)當(dāng)前的坐標(biāo)來判斷鼠標(biāo)命中了窗口的哪個(gè)部位,消息響應(yīng)函數(shù)的返回值指出了部位,例如它可能會(huì)返回HTCAPTION,或者HTCLIENT等。(其返回值有很多,請查閱MSDN)。

            知道這個(gè)就好了,我們還是要判斷下鼠標(biāo)的位置,然后通過該位置保存到result給window處理。

            其實(shí)就是我們的程序沒有邊框不能發(fā)送這些消息,我們把它告訴windows,然后windows幫我們處理拖動(dòng),改變大小等效果。所以效果和有邊框有標(biāo)題程序效果一樣的。

            頭文件申明:

            1. class MainWindow : public QMainWindow  
            2. {  
            3.     Q_OBJECT  
            4. public:  
            5.     MainWindow(QWidget *parent = 0);  
            6.     ~MainWindow();  
            7.   
            8. protected:  
            9.     bool winEvent(MSG *message, long *result);  
            10. };  
            CPP實(shí)現(xiàn)

            1. bool MainWindow::winEvent(MSG *message, long *result)  
            2. {  
            3.     switch(message->message)  
            4.     {  
            5.     case WM_NCHITTEST:  
            6.         int xPos = GET_X_LPARAM(message->lParam) - this->frameGeometry().x();  
            7.         int yPos = GET_Y_LPARAM(message->lParam) - this->frameGeometry().y();  
            8.         if(this->childAt(xPos,yPos) == 0)  
            9.         {  
            10.             *result = HTCAPTION;  
            11.         }else{  
            12.             return false;  
            13.         }  
            14.         if(xPos > 18 && xPos < 22)  
            15.             *result = HTLEFT;  
            16.         if(xPos > (this->width() - 22) && xPos < (this->width() - 18))  
            17.             *result = HTRIGHT;  
            18.         if(yPos > 18 && yPos < 22)  
            19.             *result = HTTOP;  
            20.         if(yPos > (this->height() - 22) && yPos < (this->height() - 18))  
            21.             *result = HTBOTTOM;  
            22.         if(xPos > 18 && xPos < 22 && yPos > 18 && yPos < 22)  
            23.             *result = HTTOPLEFT;  
            24.         if(xPos > (this->width() - 22) && xPos < (this->width() - 18) && yPos > 18 && yPos < 22)  
            25.             *result = HTTOPRIGHT;  
            26.         if(xPos > 18 && xPos < 22 && yPos > (this->height() - 22) && yPos < (this->height() - 18))  
            27.             *result = HTBOTTOMLEFT;  
            28.         if(xPos > (this->width() - 22) && xPos < (this->width() - 18) && yPos > (this->height() - 22) && yPos < (this->height() - 18))  
            29.             *result = HTBOTTOMRIGHT;  
            30.   
            31.         return true;  
            32.     }  
            33.     return false;  
            34. }  

            把各種邊界情況保存到result給windows處理,我們就省去很多事情,我想windows肯定比我們自己實(shí)現(xiàn)的效果要好多了。

            以上的18 以及 22 是我對(duì)程序的邊緣進(jìn)行判斷的范圍。

            因?yàn)?/p>

            我做了邊框陰影。陰影邊框設(shè)定為20px所以在

            1. xPos > 18 && xPos < 22 其實(shí)就是我們假定的邊框了。  
            1.   
            @import url(http://www.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
            posted on 2013-07-11 19:45 逛奔的蝸牛 閱讀(4178) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Qt
            久久精品国产久精国产果冻传媒| 久久久久国产精品熟女影院 | 久久WWW免费人成—看片| 久久夜色精品国产亚洲| 久久国产成人午夜AV影院| 久久综合九色综合网站| 国产精品久久久久影院色| 久久精品国产精品亚洲| 久久久久久精品免费看SSS| 国产亚洲婷婷香蕉久久精品| 久久九九久精品国产| 久久婷婷色综合一区二区| 亚洲欧美日韩精品久久| 99精品久久精品一区二区| 狠狠狠色丁香婷婷综合久久五月 | 国产成人99久久亚洲综合精品| 久久久久久青草大香综合精品| 久久精品aⅴ无码中文字字幕不卡| 久久久久国产一级毛片高清板| 综合网日日天干夜夜久久| 久久精品国产99久久久香蕉| 久久综合狠狠综合久久综合88| 日本亚洲色大成网站WWW久久 | 久久精品一区二区三区AV| 久久AⅤ人妻少妇嫩草影院| 精品国产VA久久久久久久冰| 久久九九久精品国产免费直播| 岛国搬运www久久| 国产精品免费看久久久香蕉| 精品久久久久久中文字幕| 一本色综合网久久| 久久久久久久波多野结衣高潮 | 大美女久久久久久j久久| 久久综合亚洲欧美成人| 亚洲国产精品无码久久久不卡| 一本大道久久东京热无码AV| 久久久久久无码国产精品中文字幕 | 久久综合精品国产二区无码| 99久久国产宗和精品1上映| 性做久久久久久久久老女人| 久久精品综合一区二区三区|