当前位置:网站首页>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 .
边栏推荐
- Mongodb installation and basic operation
- BN折叠及其量化
- Leetcode: Jianzhi offer 04 Search in two-dimensional array
- LeetCode:394. String decoding
- [MySQL] limit implements paging
- Improved deep embedded clustering with local structure preservation (Idec)
- [OC foundation framework] - [set array]
- [OC]-<UI入门>--常用控件-UIButton
- Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
- Advanced Computer Network Review(4)——Congestion Control of MPTCP
猜你喜欢
[OC-Foundation框架]-<字符串And日期与时间>
Intel distiller Toolkit - Quantitative implementation 3
LeetCode:498. 对角线遍历
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
QML type: locale, date
CUDA realizes focal_ loss
[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)
LeetCode:221. Largest Square
BMINF的後訓練量化實現
SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
随机推荐
Selenium+pytest automated test framework practice
Leetcode problem solving 2.1.1
Tdengine biweekly selection of community issues | phase III
[OC-Foundation框架]---【集合数组】
注意力机制的一种卷积替代方式
Li Kou daily question 1 (2)
Show slave status \ read in G_ Master_ Log_ POS and relay_ Log_ The (size) relationship of POS
[oc foundation framework] - < copy object copy >
[oc]- < getting started with UI> -- common controls uibutton
LeetCode41——First Missing Positive——hashing in place & swap
一改测试步骤代码就全写 为什么不试试用 Yaml实现数据驱动?
Pytest之收集用例规则与运行指定用例
Niuke winter vacation training 6 maze 2
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
自定义卷积注意力算子的CUDA实现
[text generation] recommended in the collection of papers - Stanford researchers introduce time control methods to make long text generation more smooth
Advanced Computer Network Review(4)——Congestion Control of MPTCP
Pytest parameterization some tips you don't know / pytest you don't know
[oc]- < getting started with UI> -- common controls - prompt dialog box and wait for the prompt (circle)
LeetCode:387. The first unique character in the string