Qt 隱藏標題欄可拖拽,自由縮放

2021-10-05 09:22:32 字數 1546 閱讀 5987

qt在隱藏標題欄的情況下,實現拖拽很簡單,可以看這裡

或者這裡:

今天主要核心是在幾年前,嘗試過qt在隱藏標題欄情況下實現可自由縮放的效果,

原來的坑在這裡:

大致就是這樣的,剩下的看下**

//標頭檔案

#ifndef mainwindow_h

#define mainwindow_h

topleft = 11,

top = 12,

topright = 13,

left = 21,

center = 22,

right = 23,

buttomleft = 31,

buttom = 32,

buttomright = 33

};class mainwindow : public qmainwindow

;#endif // mainwindow_h

//原始檔

#include "mainwindow.h"

mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent));}

void mainwindow::mousepressevent(qmouseevent *event)

else

}m_rtpregeometry = geometry();

m_ptviewmousepos = event->globalpos();

}}void mainwindow::mousemoveevent(qmouseevent *event)

else

qpoint ptcurrentpos = qcursor::pos(); //獲取當前的點,這個點是全域性的

qpoint ptmovesize = ptcurrentpos - m_ptviewmousepos; //計算出移動的位置,當前點 - 滑鼠左鍵按下的點

qrect rttempgeometry = m_rtpregeometry;

if(m_resizeflag)

this->setgeometry(rttempgeometry);}}

}void mainwindow::mousereleaseevent(qmouseevent *event)

else

}void mainwindow::mousedoubleclickevent(qmouseevent *event)

else}}

}void mainwindow::setcursorshape(int mpos)

this->setcursor(mcursor);

}int mainwindow::calcursorcol(qpoint pt)

int mainwindow::calcursorpos(qpoint pt, int colpos)

Qt自定義標題欄並實現拖拽

很多時候,qt自帶的窗體邊框不能滿足我們的需求,或者我們覺得由於系統的主題影響導致介面太醜了,我們需要自行定義乙個好看並和普通標題欄功能相同的控制項去替代,以達到美化我們的程式介面的目的 本文簡單的實現了該功能。下面是執行截圖,由於選的比較醜,所以看起來不好看 實現了滑鼠拖拽事件,沒有為標題欄新增滑...

Qt之自建標題欄

在專案中遇到linux環境重dialog在雙擊標題欄時對話方塊會最大化的情況,在設定maxmiumsize等都沒有效果的情況下所以自設標題欄。大體思路是通過三個空間組成標題欄的圖示 標題 關閉按鍵,並且通過滑鼠事件來控制框體的移動。通過繼承qdialog,將標題欄和將所要顯示的內容的widget組合...

QT 去掉標題欄和去掉標題欄後移動視窗

在用qt編寫介面時,去掉標題欄方法比較簡單,就一行 this setwindowflags qt framelesswindowhint 去掉以後又發現乙個問題,就是不能移動視窗了,於是我就重寫了三個滑鼠事件,大致 如下 h檔案的 include protected void mousepresse...