#ifndef dlgtitle_h
#define dlgtitle_h
#include
enum buttontype
;class
dlgtitle
:public qwidget
;#endif //dlgtitle_h
自定義標題欄類dlgtitle.cpp如下:
#include "dlgtitle.h"
#define button_width
42//按鈕寬度
#define button_height
32//按鈕高度
#define title_height
40//標題欄高度
dlgtitle:
:dlgtitle
(qwidget* parent)
:qwidget
(parent)
,m_ispressed
(false
)dlgtitle::~
dlgtitle()
void dlgtitle:
:init()
void dlgtitle:
:setbuttontype
(buttontype buttontype)
}//使用qss設定按鈕樣式,滑鼠樣式仿照vs2013的最小化、最大化、還原和關閉按鈕
void dlgtitle:
:setbuttonstyle()
""qpushbutton"
"qpushbutton:hover"
"qpushbutton:pressed");
m_pmaxbutton-
>
setstylesheet
("qpushbutton"
"qpushbutton"
"qpushbutton:hover"
"qpushbutton:pressed");
m_prestorebutton-
>
setstylesheet
("qpushbutton"
"qpushbutton"
"qpushbutton:hover"
"qpushbutton:pressed");
m_pclosebutton-
>
setstylesheet
("qpushbutton"
"qpushbutton"
"qpushbutton:hover"
"qpushbutton:pressed");
}void dlgtitle:
:setdlgicon
(const qstring& filename)
void dlgtitle:
:setdlgtitle
(const qstring& title)")
;}void dlgtitle:
:mousepressevent
(qmouseevent *event)
}else
return qwidget:
:mousepressevent
(event);}
void dlgtitle:
:mousereleaseevent
(qmouseevent *event)
void dlgtitle:
:mousedoubleclickevent
(qmouseevent *event)
else
}return qwidget:
:mousedoubleclickevent
(event);}
void dlgtitle:
:mousemoveevent
(qmouseevent *event)
}void dlgtitle:
:paintevent
(qpaintevent *event)
update()
;return qwidget:
:paintevent
(event);}
void dlgtitle:
:minibuttonclicked()
void dlgtitle:
:restorebuttonclicked()
void dlgtitle:
:maxbuttonclicked()
void dlgtitle:
:closebuttonclicked()
主視窗使用自定義標題欄類dlgtitle如下:
#include "customtitle.h"
#include "dlgtitle.h"
customtitle:
:customtitle
(qwidget *parent)
:qmainwindow
(parent)
void customtitle:
:init()
");//需要注意的是dlgbkgnd.png屬於標題欄位置的影象高度為title_height
}
QT 自定義標題欄
1 去除舊的標題欄 去除qdialog對話方塊有上角問號 qt windowflags flags qt dialog flags qt windowclosebuttonhint flags qt framelesswindowhint setwindowflags flags flags qt ...
Qt 個性化標題欄,自定義標題欄
目前還沒有達到自己滿意的地步,魔方別人寫的的,先提供參考,後面在加入新的東西 標頭檔案 ifndef titlebar h define titlebar h include class qlabel class qpushbutton class titlebar public qwidget e...
android自定義標題欄
1.建立自定義標題欄的xml檔案,可以給標題欄加背景 引用或者在drawable檔案下通過xml檔案生成 2.在activity中通過requestwindowfeature window.feature custom title 宣告使用自定義標題 3.setcontentview r.layou...