QAction可以理解為一個動作數據,包含了這個同坐相關的圖標、文本、是否可用等數據和狀態,以及連接對應的槽函數,用於執行這個動作。
QToolButton則可以使用QAction對象作為后端,顯示這個QAction的圖標,關聯其是否可用的狀態。
簡單示例:
QAction *exampleAction = new QAction(parent); ... (省略了設置其圖標,文本,槽函數等代碼) QToolButton *exampleButton = new QToolButton(parent); exampleButton->setDefaultAction(exampleAction); // 將 exampleButton 與 exampleAction 關聯起來