当前位置:网站首页>QML控件类型:ToolTip
QML控件类型:ToolTip
2022-07-01 01:13:00 【友善啊,朋友】
一、描述
ToolTip 继承自 Popup,可以为任何控件提供工具提示。工具提示是通知用户控件功能的一小段文本。它通常放置在父控件的上方或下方。 提示文本可以是任何富文本格式的字符串。

1.1、附加工具提示
为控件设置工具提示的最直接方法是通过附加属性指定文本和可见性。
Button {
text: qsTr("Save")
ToolTip.visible: down
ToolTip.text: qsTr("Save the active project")
}
1.2、延迟和超时
工具提示通常由于某个外部事件或用户交互而显示的,并且它们通常在某个超时后隐藏。
以下示例演示了如何延迟显示工具提示,且一旦松开按钮,工具提示就会隐藏:
Button {
text: qsTr("Button")
ToolTip.visible: pressed
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
ToolTip.text: qsTr("This tool tip is shown after pressing and holding the button down.")
}
以下示例展示了如何在将按钮悬停一秒后显示工具提示,并在超时五秒后将其隐藏:
import QtQuick
import QtQuick.Controls
Window
{
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Button
{
text: qsTr("Button")
hoverEnabled: true
ToolTip.delay: 1000
ToolTip.timeout: 5000
ToolTip.visible: hovered
ToolTip.text: qsTr("将按钮悬停一秒钟后会显示此工具提示")
}
}
1.3、自定义工具提示
以下示例提供了一个工具提示,该工具提示在拖动手柄时显示滑块的值:
Slider
{
id: slider
value: 0.5
width: 150
ToolTip {
parent: slider.handle
visible: slider.pressed
text: slider.value.toFixed(1)
}
}
二、自定义ToolTip示例
import QtQuick
import QtQuick.Controls
Window
{
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Button
{
id:btn
text: qsTr("Button")
hoverEnabled: true
ToolTip {
id: control
text: qsTr("A descriptive tool tip of what the button does")
delay: 1000
timeout: 5000
visible: btn.hovered
contentItem: Text {
text: control.text
font: control.font
color: "#21be2b"
}
background: Rectangle {
border.color: "#129bf1"
}
}
}
}
三、属性成员
1、delay : int
显示工具提示的延迟(毫秒)。默认值为 0。设置小于0也为0。
2、text : string
工具提示上显示的文本。
3、timeout : int
工具提示隐藏后的超时时间(毫秒)。负数则工具提示不会自动隐藏。默认值为 -1。
四、附加属性成员
1、ToolTip.delay : int、ToolTip.text : string、ToolTip.timeout : int
同属性成员。
2、ToolTip.toolTip : ToolTip
共享工具提示实例。此属性可以附加到任何项目。
3、ToolTip.visible : bool
共享工具提示是否可见。此属性可以附加到任何项目。
五、成员函数
1、void hide()
隐藏工具提示。
2、void show(string text, int timeout)
显示为工具提示,超时时间为 timeout 毫秒。
六、附加成员函数
1、void hide()
隐藏了共享的工具提示。此方法可以附加到任何项目。
2、void show(string text, int timeout = -1)
显示带有文本和超时时间 timeout 毫秒的共享工具提示。此方法可以附加到任何项目。
边栏推荐
- 面对产业互联网的时候,甚至还用消费互联网的方式和方法去落地和实践产业互联网
- 如何学习和阅读代码
- 小程序云开发之--微信公众号文章采集篇
- Sitge joined the opengauss open source community to jointly promote the ecological development of the database industry
- Some essential differences
- After working for 6 years, let's take stock of the golden rule of the workplace where workers mix up
- Draw some interesting figures with flutter's canvas
- How to select securities companies? In addition, is it safe to open a mobile account?
- 关于白盒测试,这些技巧你得游刃有余~
- 未来的 Web3会带来什么?
猜你喜欢
![[Qt5 tab] tab label and content hierarchical analysis](/img/cc/c8c2e79877a958f742a8e9e60ceb43.png)
[Qt5 tab] tab label and content hierarchical analysis

7-2 punch in reward DP for puzzle a

Neo4j installation, operation, project construction and function realization

electron之坑addon

Uniapp official component clicking item is invalid, solution

3dsmax plug-in development traversal node object and object acquisition and inode transformation matrix description

数据探索电商平台用户行为流失分析

The argument type 'function' can't be assigned to the parameter type 'void function()‘

VirtualBox 安装增强功能

【2022年】江西省研究生数学建模方案、代码
随机推荐
[problem handled] -nvidia SMI command cannot obtain the GPU process number of its own container and the external GPU process number
Mathematical knowledge: finding combinatorial number III - finding combinatorial number
Laravel event & Monitoring
元宇宙为 VR/AR 带来的新机会
【Content-Type请求头的内容】
[Office PDF] PDF merging and splitting will free us from the functional limitations of paid software, OK
农产品换房?“变相”购房补贴!
TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor. cpu() to copy the tensor to
More pragmatic in business
【Proteus仿真】Arduino UNO +74C922键盘解码驱动4X4矩阵键盘
微生物健康,食品微生物检测为什么很重要
gin_ gorm
一站式洞察行业热点,飞瓜数据B站新功能「流量大盘」上线!
思特奇加入openGauss开源社区,共同推动数据库产业生态发展
[fundamentals of wireless communication-14]: illustrated mobile communication technology and application development-2-the first generation mobile analog communication big brother
go导入自建包
3500字归纳总结:一名合格的软件测试工程师需要掌握的技能大全
7-2 punch in reward DP for puzzle a
微生物安全与健康,什么是生物处理?
Draw some interesting figures with flutter's canvas