当前位置:网站首页>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 .
边栏推荐
- AcWing 2456. 记事本
- LeetCode41——First Missing Positive——hashing in place & swap
- 不同的数据驱动代码执行相同的测试场景
- 随手记01
- Leetcode: Sword finger offer 48 The longest substring without repeated characters
- A convolution substitution of attention mechanism
- AcWing 2456. Notepad
- Philosophical enlightenment from single point to distributed
- Advanced Computer Network Review(3)——BBR
- BN折叠及其量化
猜你喜欢

UML diagram memory skills

Once you change the test steps, write all the code. Why not try yaml to realize data-driven?

注意力机制的一种卷积替代方式

The carousel component of ant design calls prev and next methods in TS (typescript) environment

Intel Distiller工具包-量化实现1

After reading the programmer's story, I can't help covering my chest...

Different data-driven code executes the same test scenario
![[OC]-<UI入门>--常用控件的学习](/img/2c/d317166e90e1efb142b11d4ed9acb7.png)
[OC]-<UI入门>--常用控件的学习

如何正确截取字符串(例:应用报错信息截取入库操作)

Multivariate cluster analysis
随机推荐
在QWidget上实现窗口阻塞
Super efficient! The secret of swagger Yapi
【剑指offer】序列化二叉树
LeetCode:34. Find the first and last positions of elements in a sorted array
MongoDB 的安装和基本操作
BMINF的后训练量化实现
[OC-Foundation框架]---【集合数组】
多元聚类分析
CUDA实现focal_loss
A convolution substitution of attention mechanism
使用标签模板解决用户恶意输入的问题
LeetCode:214. 最短回文串
Computer graduation design PHP Zhiduo online learning platform
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
Connexion d'initialisation pour go redis
Digital people anchor 618 sign language with goods, convenient for 27.8 million people with hearing impairment
UML圖記憶技巧
[oc foundation framework] - < copy object copy >
SimCLR:NLP中的对比学习
Leetcode: Jianzhi offer 03 Duplicate numbers in array