当前位置:网站首页>QML control type: menu
QML control type: menu
2022-07-06 09:11:00 【Friendly, friend】
One 、 describe
Menu pop ups that can be used as context menus or pop-up menus .
When used as a context menu :
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
if (mouse.button === Qt.RightButton)
contextMenu.popup()
}
onPressAndHold: {
if (mouse.source === Qt.MouseEventNotSynthesized)
contextMenu.popup()
}
Menu {
id: contextMenu
MenuItem { text: "Cut" }
MenuItem { text: "Copy" }
MenuItem { text: "Paste" }
}
}When used as a pop-up menu , The simplest way is to specify the required by using their respective properties x and y Coordinates to specify the location , And then call open() open a menu .
Button {
id: fileButton
text: "File"
onClicked: menu.open()
Menu {
id: menu
y: fileButton.height
MenuItem {
text: "New..."
}
MenuItem {
text: "Open..."
}
MenuItem {
text: "Save"
}
}
}You can also do it in Menu Create a submenu in and declare Action object :
Menu {
Action { text: "Cut" }
Action { text: "Copy" }
Action { text: "Paste" }
MenuSeparator { }
Menu {
title: "Find/Replace"
Action { text: "Find Next" }
Action { text: "Find Previous" }
Action { text: "Replace" }
}
}By default , Submenus are cascaded on desktop platforms with available mouse cursors . Non cascading menus display one menu at a time , And focus on the parent menu .
Usually , Menu items are statically declared as sub items of the menu , but Menu Also provide API To dynamically add 、 Insert 、 Move and delete items .
Two 、 Attribute members
1、cascade : bool
Whether the menu cascades its submenus . The default value is platform specific .
Non cascading menus display one menu at a time , And focus on the parent menu .
Be careful : Changing the value of this property when the menu is open is invalid .
2、[default] contentData : list<Object>
Content data list .
The list is contained in QML All objects declared as menu sub items in , And use addItem() and insertItem() Method to dynamically add or insert items .
Be careful : And contentChildren Different ,contentData It does contain non visual QML object . Items are not reordered when inserted or moved .
3、【 read-only 】contentModel : model
Model for displaying menu items .
Provide a content model for visualization purposes . It can be assigned as a model to content items that render menu content .
Menu {
id: menu
contentItem: ListView {
model: menu.contentModel
}
}4、【 read-only 】count : int
Number of projects .
5、currentIndex : int
Index of the currently highlighted item . Menu items can be highlighted by mouse over or keyboard navigation .
6、delegate : Component
Components for creating projects to render actions .
Menu {
Action { text: "Cut" }
Action { text: "Copy" }
Action { text: "Paste" }
}7、focus : bool
Whether the pop-up window needs focus . The default is false.
When the pop-up window actually gets the focus ,activeFocus Will be for true.
8、overlap : real
The number of pixels that the menu overlaps horizontally with its parent menu . The default is style specific .
This attribute is only valid if the menu is used as a cascading submenu .
It is invalid to change the value of the property when the menu is opened .
9、title : string
The title of the menu .
When the menu is a submenu , The title of the menu is usually displayed in the text of the menu item , And when it's in the menu bar , Is displayed in the text of the tool button .
3、 ... and 、 Member functions
1、void popup(Item parent, real x, real y, MenuItem item = null)
void popup(real x, real y, MenuItem item = null)
The specified position in the pop-up coordinate system x, y Open menu at , That is, the coordinates relative to its parent .
Menus can be selected to align with specific menu items .
void popup(Item parent, point pos, MenuItem item = null)
void popup(point pos, MenuItem item = null)
The specified position in the pop-up coordinate system pos Open menu at , That is, the coordinates relative to its parent .
Menus can be selected to align with specific menu items .
void popup(Item parent, MenuItem item = null)
void popup(MenuItem item = null)
Open the menu at the mouse cursor , Otherwise, put the menu in the center of its parent .
Menus can be selected to align with specific menu items .
2、Action actionAt(int index)
Returns... At index action , If the index is invalid or there is no operation at the specified index , Then return to null.
3、void addAction(Action action)
Add actions to the end of this menu .
4、void addItem(Item item)
Will be added to the end of the item list .
5、void addMenu(Menu menu)
Add the menu as a submenu to the end of this menu .
6、void dismiss()
Close all menus in the hierarchy to which this menu belongs .
Be careful : With only closing the menu and its submenus close() Different ,dismiss() Close the entire hierarchy of the menu , Include parent menu .
7、void insertAction(int index, Action action)
Insert action at index . The index is located in all items in the menu .
8、void insertItem(int index, Item item)
Insert item at index .
9、void insertMenu(int index, Menu menu)
Insert a menu at the index as a submenu . The index is located in all items in the menu .
10、Item itemAt(int index)
Returns the item at the index , Returns if it does not exist null.
11、Menu menuAt(int index)
Return to the submenu at the index , If the index is invalid or there is no submenu at the specified index , Then return to null.
12、void moveItem(int from, int to)
Index from Items at move to index to.
13、void removeAction(Action action)
Delete and destroy the specified action .
14、void removeItem(Item item)
Remove and destroy the specified items .
15、void removeMenu(Menu menu)
Delete and destroy the specified menu .
16、Action takeAction(int index)
Delete and return the action at the index . The index is located in all items in the menu . Ownership of the action is transferred to the caller .
17、MenuItem takeItem(int index)
Delete and return the item at the index . Ownership of the item is transferred to the caller .
18、Menu takeMenu(int index)
Delete and return index Menu at . The index is located in all items in the menu .
Ownership of the menu is transferred to the caller .
边栏推荐
- What is MySQL? What is the learning path of MySQL
- 在QWidget上实现窗口阻塞
- 力扣每日一题(二)
- Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
- Intel distiller Toolkit - Quantitative implementation 1
- LeetCode:124. Maximum path sum in binary tree
- Advanced Computer Network Review(3)——BBR
- LeetCode:162. Looking for peak
- Advanced Computer Network Review(5)——COPE
- 七层网络体系结构
猜你喜欢
随机推荐
Opencv+dlib realizes "matching" glasses for Mona Lisa
A convolution substitution of attention mechanism
How to intercept the string correctly (for example, intercepting the stock in operation by applying the error information)
Cesium draw points, lines, and faces
Detailed explanation of dynamic planning
BMINF的後訓練量化實現
Improved deep embedded clustering with local structure preservation (Idec)
Redis之核心配置
Advanced Computer Network Review(3)——BBR
CSP first week of question brushing
postman之参数化详解
[three storage methods of graph] just use adjacency matrix to go out
CSP student queue
Selenium+Pytest自动化测试框架实战
AcWing 2456. Notepad
Mise en œuvre de la quantification post - formation du bminf
Problems encountered in connecting the database of the project and their solutions
Simclr: comparative learning in NLP
Intel distiller Toolkit - Quantitative implementation 1
一篇文章带你了解-selenium工作原理详解



![[sword finger offer] serialized binary tree](/img/e2/25c9322da3acda06c4517b0c50f81e.png)



![[OC]-<UI入门>--常用控件的学习](/img/2c/d317166e90e1efb142b11d4ed9acb7.png)

