1、去除舊的標題欄
2、自定義新的標題欄//去除qdialog對話方塊有上角問號
qt::windowflags flags=qt::dialog;flags |=qt::windowclosebuttonhint;flags |=qt::framelesswindowhint;
setwindowflags(flags);
flags |=qt::framelesswindowhint;的意思是去除標題欄
參考自
mainwindow.h 裡面加
mainwindow.cpp裡面加private slots: void on_actionminimize_triggered(); //最小化視窗
void on_actionclose_triggered(); //關閉視窗
void on_actionmaximize_triggered(); //最大化視窗
int width = this->width();//獲取介面的寬度
qtoolbutton *minbutton = new qtoolbutton(this); //最小按鈕
qtoolbutton *helpbutton = new qtoolbutton(this); //幫助按鈕
qtoolbutton *closebutton= new qtoolbutton(this); //關閉按鈕
qtoolbutton *maxbutton = new qtoolbutton(this); //最大按鈕
qtoolbutton *menubutton = new qtoolbutton(this); //選單按鈕
qtoolbutton *normalbutton = new qtoolbutton(this);
qtoolbutton *shadebutton = new qtoolbutton(this);
qtoolbutton *unshadebutton = new qtoolbutton(this);
connect(minbutton, signal(clicked()), this, slot(on_actionminimize_triggered())); connect(closebutton, signal(clicked()), this, slot(on_actionclose_triggered())); connect(maxbutton, signal(clicked()), this, slot(on_actionmaximize_triggered())); //獲取最小化、關閉按鈕圖示
qpixmap minpix = style()->standardpixmap(qstyle::sp_titlebarminbutton);
qpixmap helppix = style()->standardpixmap(qstyle::sp_titlebarcontexthelpbutton); qpixmap closepix = style()->standardpixmap(qstyle::sp_titlebarclosebutton);
qpixmap maxpix = style()->standardpixmap(qstyle::sp_titlebarmaxbutton);
qpixmap shadepix = style()->standardpixmap(qstyle::sp_titlebarshadebutton);
qpixmap unshadepix = style()->standardpixmap(qstyle::sp_titlebarunshadebutton); qpixmap normalpix = style()->standardpixmap(qstyle::sp_titlebarnormalbutton);
qpixmap menupix = style()->standardpixmap(qstyle::sp_titlebarmenubutton); //設定最小化、關閉按鈕圖示
minbutton->seticon(minpix);
closebutton->seticon(closepix);
helpbutton->seticon(helppix);
maxbutton->seticon(maxpix);
shadebutton->seticon(shadepix);
unshadebutton->seticon(unshadepix);
normalbutton->seticon(normalpix);
menubutton->seticon(menupix); //設定最小化、關閉按鈕在介面的位置 normalbutton->setgeometry(width-160, 0, 20, 20);
menubutton->setgeometry(width-140, 0, 20, 20);
minbutton->setgeometry(width-120,0,20,20);
closebutton->setgeometry(width-100,0,20,20);
helpbutton->setgeometry(width-80,0,20,20);
maxbutton->setgeometry(width-60, 0, 20, 20);
shadebutton->setgeometry(width-40,0, 20, 20);
unshadebutton->setgeometry(width-20, 0, 20, 20); //設定滑鼠移至按鈕上的提示資訊 minbutton->settooltip(tr("最小化"));
closebutton->settooltip(tr("關閉")); m
axbutton->settooltip(tr("最大化")); //設定最小化、關閉等按鈕的樣式 minbutton->setstylesheet("background-color:transparent;"); closebutton->setstylesheet("background-color:transparent;"); normalbutton->setstylesheet("background-color:transparent;"); menubutton->setstylesheet("background-color:transparent;"); helpbutton->setstylesheet("background-color:transparent;"); maxbutton->setstylesheet("background-color:transparent;"); shadebutton->setstylesheet("background-color:transparent;"); unshadebutton->setstylesheet("background-color:transparent;");
void mainwindow::on_actionminimize_triggered()
void mainwindow::on_actionclose_triggered()
void mainwindow::on_actionmaximize_triggered()
QT自定義標題欄
ifndef dlgtitle h define dlgtitle h include enum buttontype class dlgtitle public qwidget endif dlgtitle h自定義標題欄類dlgtitle.cpp如下 include dlgtitle.h def...
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...