当前位置:网站首页>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 .
边栏推荐
- LeetCode:39. 组合总和
- QDialog
- [today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
- go-redis之初始化連接
- LeetCode:387. The first unique character in the string
- Post training quantification of bminf
- Show slave status \ read in G_ Master_ Log_ POS and relay_ Log_ The (size) relationship of POS
- Redis之性能指标、监控方式
- After reading the programmer's story, I can't help covering my chest...
- Improved deep embedded clustering with local structure preservation (Idec)
猜你喜欢
Selenium+pytest automated test framework practice (Part 2)
CUDA implementation of self defined convolution attention operator
Advanced Computer Network Review(4)——Congestion Control of MPTCP
[oc foundation framework] - < copy object copy >
Mise en œuvre de la quantification post - formation du bminf
[OC-Foundation框架]---【集合数组】
一篇文章带你了解-selenium工作原理详解
Pytest参数化你不知道的一些使用技巧 /你不知道的pytest
多元聚类分析
项目连接数据库遇到的问题及解决
随机推荐
Selenium+pytest automated test framework practice (Part 2)
[text generation] recommended in the collection of papers - Stanford researchers introduce time control methods to make long text generation more smooth
Detailed explanation of dynamic planning
AcWing 2456. Notepad
Mongodb installation and basic operation
BMINF的后训练量化实现
【文本生成】论文合集推荐丨 斯坦福研究者引入时间控制方法 长文本生成更流畅
Redis之Bitmap
LeetCode:162. Looking for peak
[OC-Foundation框架]--<Copy对象复制>
Intel Distiller工具包-量化实现2
Intel distiller Toolkit - Quantitative implementation 3
CUDA implementation of self defined convolution attention operator
In depth analysis and encapsulation call of requests
QML type: locale, date
[oc foundation framework] - < copy object copy >
[MySQL] limit implements paging
Advanced Computer Network Review(3)——BBR
Advanced Computer Network Review(3)——BBR
[shell script] use menu commands to build scripts for creating folders in the cluster