当前位置:网站首页>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 .
边栏推荐
- LeetCode41——First Missing Positive——hashing in place & swap
- In depth analysis and encapsulation call of requests
- 在QWidget上实现窗口阻塞
- Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
- LeetCode:41. Missing first positive number
- Improved deep embedded clustering with local structure preservation (Idec)
- 使用标签模板解决用户恶意输入的问题
- BN折叠及其量化
- LeetCode:236. The nearest common ancestor of binary tree
- Simclr: comparative learning in NLP
猜你喜欢
Intel Distiller工具包-量化实现3
Pytest's collection use case rules and running specified use cases
KDD 2022论文合集(持续更新中)
Intel distiller Toolkit - Quantitative implementation 3
Computer graduation design PHP Zhiduo online learning platform
LeetCode:221. Largest Square
Mongodb installation and basic operation
[oc]- < getting started with UI> -- common controls uibutton
一篇文章带你了解-selenium工作原理详解
QML type: locale, date
随机推荐
Redis之五大基础数据结构深入、应用场景
多元聚类分析
Intel distiller Toolkit - Quantitative implementation 1
Advanced Computer Network Review(4)——Congestion Control of MPTCP
UML图记忆技巧
[OC-Foundation框架]-<字符串And日期与时间>
Intel Distiller工具包-量化实现3
go-redis之初始化連接
什么是MySQL?MySql的学习之路是怎样的
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Using C language to complete a simple calculator (function pointer array and callback function)
LeetCode:214. 最短回文串
MYSQL卸载方法与安装方法
在QWidget上实现窗口阻塞
【剑指offer】序列化二叉树
[oc foundation framework] - < copy object copy >
[sword finger offer] serialized binary tree
Advanced Computer Network Review(4)——Congestion Control of MPTCP
AcWing 2456. Notepad
What is an R-value reference and what is the difference between it and an l-value?