QT6 源(111):閱讀與注釋菜單欄 QMenuBar,進行屬性與成員函數測試,信號與槽函數測試,并給出源碼

(1)

在這里插入圖片描述

(2)

在這里插入圖片描述

(3)

在這里插入圖片描述

++

在這里插入圖片描述

(4)

在這里插入圖片描述

(5)

在這里插入圖片描述

(6)

在這里插入圖片描述

(7)以下源代碼來自于頭文件 qmenubar . h

#ifndef QMENUBAR_H
#define QMENUBAR_H#include <QtWidgets/qtwidgetsglobal.h>
#include <QtWidgets/qmenu.h>QT_REQUIRE_CONFIG(menubar);QT_BEGIN_NAMESPACE //說明本菜單欄定義于 Qt的全局命名空間class QMenuBarPrivate;
class QStyleOptionMenuItem;
class QWindowsStyle;
class QPlatformMenuBar;/*
The QMenuBar class provides a horizontal menu bar.不需要設置菜單欄。它會自動將其幾何形狀設置為父控件的頂部,并在父控件重新調整大小時適當地進行更改。Usage:
在大多數主要窗口樣式應用程序中,
您將使用QMainWindow中提供的menuBar()函數,將QMenus添加到菜單欄中,并將QActions添加到彈出菜單中。可以通過使用QWidgetAction類的實例來將小部件添加到菜單中。
然后,可以使用通常的方式將這些動作插入菜單中;請參閱QMenu文檔以獲取詳細信息。Platform Dependent Look and Feel:
不同的平臺對菜單欄的外觀以及用戶與菜單欄交互時的行為有不同的要求。
例如,Windows 系統通常配置為僅在按下 AIt 鍵時顯示帶下劃線的字符助記符,
這些助記符指示菜單欄中項目的鍵盤快捷方式。QMenuBar as a Global Menu Bar :
在macOs和某些Linux桌面環境中,如Ubuntu Unity,
QMenuBar是用于使用系統級菜單欄的包裝器.
如果在同一個對話框中有多個菜單欄,
則最外面的菜單欄(通常位于具有widget標志Qt::Window的widget中)將用于系統級菜單欄。
...........*/class Q_WIDGETS_EXPORT QMenuBar : public QWidget
{Q_OBJECT//此屬性包含彈出窗口的方向. 默認彈出窗口的方向。默認情況下,菜單會“向下”彈出屏幕。//通過將屬性設置為true,菜單將“向上”彈出。您可以將此調用用于位于它們所指向的文檔下方的菜單。//如果菜單無法在屏幕上顯示,則自動使用其他方向。Q_PROPERTY(bool      defaultUp       //決定下拉菜單的彈出方向,默認向下彈出。READ   isDefaultUp       WRITE   setDefaultUp)Q_PROPERTY(bool      nativeMenuBar   //本屬性在 windows系統上無用READ   isNativeMenuBar   WRITE   setNativeMenuBar)//這個屬性表示在支持它的平臺上是否將使用菜單欄作為原生菜單欄。//此屬性指定是否應在支持的平臺上將菜單欄用作原生菜單欄。目前支持的平臺是macOS和Linux桌面,//它們使用com,canonical.dbusmeny D-Bus接口(例如Ubuntu Unity)。//如果此屬性為真,則菜單欄在原生菜單欄中使用,不在其父窗口中;如果為假,則菜單欄保留在窗口中。//在其他平臺上,設置此屬性沒有影響,讀取此屬性將始終返回假。//默認情況下,會遵循是否為該應用程序設置了 Qt:AA_DontUseNativeMenuBar屬性。//顯式設置此屬性會覆蓋屬性的存在(或不存在)。private:Q_DECLARE_PRIVATE(QMenuBar)Q_DISABLE_COPY(QMenuBar)Q_PRIVATE_SLOT(d_func(), void _q_actionTriggered())Q_PRIVATE_SLOT(d_func(), void _q_actionHovered())Q_PRIVATE_SLOT(d_func(), void _q_internalShortcutActivated(int))Q_PRIVATE_SLOT(d_func(), void _q_updateLayout())friend class QMenu        ; //本菜單欄類的友元類是菜單 QMenufriend class QMenuPrivate ;friend class QWindowsStyle;public:explicit QMenuBar(QWidget * parent = nullptr);~QMenuBar();//   Q_PROPERTY(bool      defaultUp       //決定下拉菜單的彈出方向,默認向下彈出。
//              READ    isDefaultUp       WRITE   setDefaultUp)bool    isDefaultUp() const;void   setDefaultUp(bool);//   Q_PROPERTY(bool      nativeMenuBar   //本屬性在 windows系統上無用
//              READ    isNativeMenuBar   WRITE   setNativeMenuBar)bool    isNativeMenuBar() const;void   setNativeMenuBar(bool nativeMenuBar);QPlatformMenuBar *  platformMenuBar(); //無注釋//菜單欄里的按鈕是由 QMenu::menuAction()得到的。//總結:以為菜單欄里插入的是菜單,其實插入的是對應代表菜單的按鈕QAction。//Returns the QAction that is currently highlighted, if any, else nullptr.QAction  *     activeAction() const;   //顯示菜單欄上被高亮顯示的按鈕void        setActiveAction(QAction * action);//Sets the currently highlighted action to action.//這倆函數的意思是不必為每個按鈕單獨設置觸發與高亮函數,只為按鈕的容器,菜單欄或菜單設計槽函數即可。//Returns the widget on the left of the first or on the right of the last menu item,//  depending on corner.//Note: Using a corner other than Qt::TopRightCorner or//                                Qt::TopLeftCorner will result in a warning.//enum Qt::Corner { TopLeftCorner    = 0, TopRightCorner    = 1,//                  BottomLeftCorner = 2, BottomRightCorner = 3  };QWidget  *     cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const;void        setCornerWidget(QWidget * w,Qt::Corner corner = Qt::TopRightCorner);//This sets the given w to be shown directly on the left of the first menu item,//or on the right of the last menu item, depending on corner.//The menu bar takes ownership of widget, reparenting it into the menu bar.//However, if the corner already contains a widget,//this previous widget will no longer be managed and will still be a//  visible child of the menu bar.QSize           sizeHint() const override;QSize    minimumSizeHint() const override;int                  heightForWidth(int) const override;QRect               actionGeometry(QAction *) const;   //因為本菜單欄也可以直接管理按鈕QAction          *  actionAt(const QPoint  &) const;   //略,這倆函數在 QMenu里也出現過void clear(); //Removes all the actions from the menu bar.//This convenience function inserts menu before action before and returns the//  menus menuAction(). //把菜單 menu 放到 before的前面,并返回 menu對應的 QActionQAction *  insertMenu(QAction * before, QMenu * menu); //在菜單里也可以插入子菜單QAction *     addMenu(QMenu   * menu); //在菜單欄的末尾追加菜單,返回菜單對應的按鈕。//Appends menu to the menu bar. Returns the menu's menuAction().//The menu bar does not take ownership of the menu.QMenu   *     addMenu(const QString & title);//生成一個菜單,其對應的按鈕項叫 title//Appends a new QMenu with title to the menu bar.//The menu bar takes ownership of the menu. Returns the new menu.QMenu   *     addMenu(const QIcon   & icon, const QString & title);//Appends a new QMenu with icon and title to the menu bar.//The menu bar takes ownership of the menu. Returns the new menu.//This convenience function creates a new separator action,//i.e. an action with QAction::isSeparator() returning true.//The function inserts the newly created action into this menu bar's list of//  actions before action before and returns it.QAction *  insertSeparator(QAction * before); //在菜單欄里 before按鈕的前面插入分隔符QAction *     addSeparator();                 //Appends a separator to the menu.//經測試,新添加的分隔符的容器父類,就是菜單欄。但經測試,菜單欄里似乎不允許或不顯示添加的分隔符。//該 addAction() 函數的正確用法如下:可見 QMenu::menuAction()這個函數很重要!!//    menubar->addAction(menu_F->menuAction());        //為菜單欄添加"文件(&F)"菜單//    menu_F ->setTitle(//          QCoreApplication::translate("MainWindow",  //設置菜單的名字,以及快捷鍵//             "\346\226\207\344\273\266(&F)", nullptr));using QWidget::addAction;//void  QWidget::addAction(QAction * action);QAction * addAction(const QString & text);  //說明菜單欄里可以添加普通按鈕//This convenience function creates a new action with text.//The function adds the newly created action to the menu's list of actions,//  and returns it.QAction * addAction(const QString & text,   //為菜單欄創建按鈕,并為其指定槽函數。const QObject * receiver, const char * member);// addAction(QString)://Connect to a QObject slot / functor or function pointer (with context)template<typename Obj, typename Func1>inline typename std::enable_if<!std::is_same<const char *, Func1>::value&&   QtPrivate::IsPointerToTypeDerivedFromQObject<Obj *>::Value,QAction *>::typeaddAction(const QString & text, const Obj * object, Func1 slot){   //把創建的文本為 text的按鈕的 triggered()信號連接到形參 object的 slot槽函數上QAction * result = addAction(text);connect(result, & QAction::triggered, object, std::move(slot));return result;}// addAction(QString)://Connect to a functor or function pointer (without context)template <typename Func1>inline QAction * addAction(const QString & text, Func1 slot){   //把創建的 text按鈕的信號連接到全局槽函數 slot上。QAction * result = addAction(text);connect(result, & QAction::triggered, std::move(slot));return result;}public Q_SLOTS:void setVisible(bool visible) override; //菜單欄消失,窗體整體上移,工具欄占據了菜單欄的位置。//Reimplements an access function for property: QWidget::visible.Q_SIGNALS://This signal is emitted when an action in a menu belonging to this menubar//is triggered as a result of a mouse click;    //注意上面的話:an action in a menu//action is the action that caused the signal to be emitted.//Note: QMenuBar has to have ownership of the QMenu in order this signal to work.//Normally, you connect each menu action to a single slot using QAction::triggered(),//but sometimes you will want to connect several items to a single slot//(most often if the user selects from an array). This signal is useful in such cases.//即使菜單欄里的按鈕被敲擊,也不會觸發 triggered()信號。void triggered(QAction * action); //菜單欄里的菜單里的按鈕被鼠標敲擊,才觸發本信號。void   hovered(QAction * action); //菜單欄里的按鈕高亮時觸發本信號。注意這倆信號對按鈕的區別。//This signal is emitted when a menu action is highlighted;//action is the action that caused the event to be sent.//Often this is used to update status information.protected:virtual void initStyleOption(QStyleOptionMenuItem * option,const        QAction * action) const;bool             eventFilter(QObject *, QEvent *) override;bool             event(QEvent       *) override;void       changeEvent(QEvent       *) override;void     keyPressEvent(QKeyEvent    *) override;void mouseReleaseEvent(QMouseEvent  *) override;void   mousePressEvent(QMouseEvent  *) override;void    mouseMoveEvent(QMouseEvent  *) override;void        leaveEvent(QEvent       *) override;void        paintEvent(QPaintEvent  *) override;void       resizeEvent(QResizeEvent *) override;void       actionEvent(QActionEvent *) override;void     focusOutEvent(QFocusEvent  *) override;void      focusInEvent(QFocusEvent  *) override;void        timerEvent(QTimerEvent  *) override;}; //完結 class QMenuBar : public QWidgetQT_END_NAMESPACE#endif // QMENUBAR_H

(8)

謝謝

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/81696.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/81696.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/81696.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Leetcode 3552. Grid Teleportation Traversal

Leetcode 3552. Grid Teleportation Traversal 1. 解題思路2. 代碼實現 題目鏈接&#xff1a;3552. Grid Teleportation Traversal 1. 解題思路 這一題的話核心就是一個廣度優先遍歷&#xff0c;我們只需要從原點開始&#xff0c;一點點考察其所能到達的位置&#xff0c;直至…

2023CCPC河南省賽暨河南邀請賽個人補題ABEFGHK

Dashboard - 2023 CCPC Henan Provincial Collegiate Programming Contest - Codeforces 過題難度&#xff1a;A H F G B K E 銅獎&#xff1a; 2 339 銀獎&#xff1a; 3 318 金獎&#xff1a; 5 523 A: 直接模擬 // Code Start Here int t;cin >> t;while(t-…

如何用Python批量解壓ZIP文件?快速解決方案

如何用Python批量解壓ZIP文件&#xff1f;快速解決方案 文章目錄 **如何用Python批量解壓ZIP文件&#xff1f;快速解決方案**代碼結果詳細解釋 話不多說&#xff0c;先上干貨&#xff01;&#xff01;&#xff01; 代碼 import os import zipfiledef unzip_file(dir_path: str…

Spring Boot 的高級特性與經典的設計模式應用

目錄 1. 設計模式在 Spring Boot 中的應用 1.1 單例模式&#xff1a;Bean 管理與全局實例 1.1.1 Spring 中的單例 Bean 1.1.2 自定義單例實現 1.1.3 單例模式的優勢 1.2 工廠模式&#xff1a;動態創建 Bean 1.2.1 Spring 的工廠方法 1.2.2 自定義工廠類 1.2.3 工廠模式…

在Excel中使用函數公式時,常見錯誤對應不同的典型問題

在Excel中使用函數公式時&#xff0c;常見錯誤對應不同的典型問題 1. #DIV/0!&#xff08;除以零錯誤&#xff09;2. #N/A&#xff08;值不可用&#xff09;3. #NAME?&#xff08;名稱錯誤&#xff09;4. #NULL!&#xff08;空交集錯誤&#xff09;5. #NUM!&#xff08;數值錯…

【cursor疑惑】cursor續杯后使用agent對話時,提示“需要pro或商業訂閱的用戶才能使用“

背景 cursor的pro會員體驗過期了&#xff0c;想再次體驗deepseek、Claude等agent對話提示:“免費版本不可以使用agent對話功能(英文忘記截圖了&#xff0c;大意是這樣)”。 處理方法 Step-1&#xff1a;再次續杯cursor的pro會員14天體驗 詳情&#xff0c;見&#xff1a;【c…

解決qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed

可以參考&#xff1a;解決qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed-CSDN博客 講的是程序執行目錄下可能缺少了&#xff1a; libssl-1_1-x64.dll 和 libcrypto-1_1-x64.dll 庫文件&#xff0c;將其復制到可執行文件exe的同級目錄下即可…

白楊SEO:不到7天,白楊SEO博客網站百度搜索顯示和排名恢復正常!順帶說說上海線下GEO聚會分享和播客紅利

大家好&#xff0c;我是白楊SEO&#xff0c;專注SEO十年以上&#xff0c;全網SEO流量實戰派&#xff0c;AI搜索優化研究者。 5月開始&#xff0c;明顯就忙起來了&#xff0c;不管是個人陪跑還是企業顧問&#xff0c;不管是需要傳統SEO還是新媒體流量&#xff0c;還是當下這個A…

FART 自動化脫殼框架簡介與脫殼點的選擇

版權歸作者所有&#xff0c;如有轉發&#xff0c;請注明文章出處&#xff1a;https://cyrus-studio.github.io/blog/ FART簡介 ART 環境下基于主動調用的自動化脫殼方案&#xff0c;可以解決函數抽取殼。 關于函數抽取殼的實現原理可以參考&#xff1a;基于 art 下的類加載機…

卷積神經網絡進階:轉置卷積與棋盤效應詳解

【內容摘要】 本文深入解析卷積神經網絡中的轉置卷積&#xff08;反卷積&#xff09;技術&#xff0c;重點闡述標準卷積與轉置卷積的計算過程、轉置卷積的上采樣作用&#xff0c;以及其常見問題——棋盤效應的產生原因與解決方法&#xff0c;為圖像分割、超分辨率等任務提供理論…

Redis進階知識

Redis 1.事務2. 主從復制2.1 如何啟動多個Redis服務器2.2 監控主從節點的狀態2.3 斷開主從復制關系2.4 額外注意2.5拓撲結構2.6 復制過程2.6.1 數據同步 3.哨兵選舉原理注意事項 4.集群4.1 數據分片算法4.2 故障檢測 5. 緩存5.1 緩存問題 6. 分布式鎖 1.事務 Redis的事務只能保…

SDC命令詳解:使用get_libs命令進行查詢

相關閱讀 SDC命令詳解https://blog.csdn.net/weixin_45791458/category_12931432.html?spm1001.2014.3001.5482 get_libs命令用于創建一個庫對象集合&#xff0c;關于設計對象和集合的更詳細介紹&#xff0c;可以參考下面的博客。需要注意的是&#xff0c;在有些工具中還存在…

idea2024 不知道安裝了什么插件,界面都是中文的了,不習慣,怎么修改各個選項改回英文

如果你的 IntelliJ IDEA 2024 突然變成中文界面&#xff0c;很可能是安裝了中文語言包插件&#xff08;如 “Chinese (Simplified) Language Pack”&#xff09;。以下是 徹底恢復英文界面 的方法&#xff1a; 方法 1&#xff1a;直接卸載中文插件&#xff08;推薦&#xff09;…

物流項目第二期(用戶端登錄與雙token三驗證)

第一期內容&#xff1a; 物流項目第一期&#xff08;登錄業務&#xff09;-CSDN博客 用戶端登錄 實現分析 登錄功能 Data public class UserLoginRequestVO {ApiModelProperty("登錄臨時憑證")private String code;ApiModelProperty("手機號臨時憑證"…

精準掌控張力動態,重構卷對卷工藝設計

一、MapleSim Web Handling Library仿真和虛擬調試解決方案 在柔性材料加工領域&#xff0c;卷對卷&#xff08;Roll-to-Roll&#xff09;工藝的效率與質量直接決定了產品競爭力。如何在高動態生產場景中實現張力穩定、減少斷裂風險、優化加工速度&#xff0c;是行業長期面臨的…

Voxblox算法

文章目錄 1. 算法簡介2. 由 TSDF 構建 ESDF 的方法2.1. 論文解讀2.2. 偽代碼實現 1. 算法簡介 Voxblox 算法出現于文獻《Voxblox: Incremental 3D Euclidean Signed Distance Fields for On-Board MAV Planning》&#xff0c;PDF 鏈接&#xff1a;https://arxiv.org/pdf/1611.…

計算機圖形學基礎--Games101筆記(一)數學基礎與光柵化

文章目錄 數學基礎向量插值三角形插值雙線性插值 平面定義法線-點表示 第一部分&#xff1a;光柵化坐標變換二維變換3D變換視圖變換&#xff08;MVP&#xff09;投影變換 光柵化采樣抗鋸齒&#xff08;反走樣&#xff09;可見性&#xff08;遮擋&#xff09; 著色與紋理Blinn-P…

@RequestParam 和 @RequestBody、HttpServletrequest 與HttpServletResponse

在Java Web開發中&#xff0c;RequestParam、RequestBody、HttpServletRequest 和 HttpServletResponse 是常用的組件&#xff0c;它們用于處理HTTP請求和響應。下面分別介紹它們的使用場景和使用方法&#xff1a; 1. RequestParam RequestParam 是Spring MVC框架中的注解&am…

【硬核數學】2. AI如何“學習”?微積分揭秘模型優化的奧秘《從零構建機器學習、深度學習到LLM的數學認知》

在上一篇中&#xff0c;我們探索了線性代數如何幫助AI表示數據&#xff08;向量、矩陣&#xff09;和變換數據&#xff08;矩陣乘法&#xff09;。但AI的魅力遠不止于此&#xff0c;它最核心的能力是“學習”——從數據中自動調整自身&#xff0c;以做出越來越準確的預測或決策…

10.15 LangChain v0.3重磅升級:Tool Calling技術顛覆大模型工具調用,效率飆升300%!

LangChain v0.3 技術生態與未來發展:支持 Tool Calling 的大模型 關鍵詞:LangChain Tool Calling, 大模型工具調用, @tool 裝飾器, ToolMessage 管理, Few-shot Prompting 1. Tool Calling 的技術革新 LangChain v0.3 的工具調用(Tool Calling)功能標志著大模型應用開發進…