QT學習記錄 選單欄工具欄狀態列

2021-10-04 04:57:48 字數 1888 閱讀 8049

選單欄

qmenubar *mbar =

menubar()

;//建立選單欄

1.qmenu *pfile = mabr-

>

addmenu

("檔案");

//建立選單,mainwindow上本來就有選單欄、工具欄、狀態列,直接通過介面獲取就行

2.qmenu *pfile =

newqmenu

("檔案");

mbar-

>

addmenu

(pfile)

;1.qaction *pnew = pfile-

>

addaction

("新建");

//建立選單的選單項

2.qaction *pnew =

newqaction

("新建");

//建立選單項

pfile-

>

addaction

(pnew)

;//給選單新增選單項

pfile-

>

addseparator()

;//給選單項之間新增分隔欄

//工具欄

q******* ******** =

this

->

add*******

("工具欄");

//建立工具欄

*******-

>

addaction

(pnew)

;//選單項的觸發訊號:triggered();

//工具欄可以新增按鈕

//按鈕也可以設定成選單

滑鼠右鍵彈出選單

qmenu *menu =

new qmenu;

qaction *modifyaction =

newqaction

(qstringliteral

("修改"),

this);

qaction *delaction =

newqaction

(qstringliteral

("刪除"),

this);

menu-

>

addaction

(modifyaction)

;menu-

>

addaction

(delaction)

;menu-

>

exec

(qcursor::

pos())

;//滑鼠右擊顯示選單

//浮動資訊

//qt通過qtooptip顯示浮動資訊

//滑鼠移動事件下

qtooltip::

showtext

(event-

>globalpos,

"資訊內容"

);

//狀態列

qstatusbar *stbar =

statusbar()

;qlabel *label =

newqlabel

(this

,"label");

stbar-

>

addwidget

(label)

;//從狀態列左邊開始新增widget

stbar-

>

addpermanentwidget

(label)

;//從狀態列右邊開始新增

//mainwidget視窗可以新增核心視窗,使用setcentralwidget()函式

Qt 38 選單欄 工具欄 狀態列

待續 等到當前工具欄按鈕的格式 qt toolbuttonstyle toolbuttonstyle const 設定當前工具欄按鈕的格式 void settoolbuttonstyle qt toolbuttonstyle toolbuttonstyle 使用的方式 如果是控制台應用程式,則需要使...

Qt學習筆記 選單欄 工具欄和狀態列

在 動作 筆記中有如下 openaction new qaction qicon images doc open tr open.this openaction setshortcuts qkeysequence open openaction setstatustip tr open an exi...

(12)選單欄 工具欄和狀態列

openaction new qaction qicon images doc open tr open.this openaction setshortcuts qkeysequence open openaction setstatustip tr open an existing file c...