当前位置:网站首页>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 毫秒的共享工具提示。此方法可以附加到任何项目。
边栏推荐
- Ks009 implementation of pet management system based on SSH
- laravel 事件 & 监听
- C # customize and dynamically switch cursor
- The argument type 'function' can't be assigned to the parameter type 'void function()‘
- 亲测有效,快速创建JMeter桌面快捷方式
- With regard to the white box test, you have to master these skills~
- 【动态规划】路径dp:931. Minimum Falling Path Sum
- Winodws 快速添加开机启动项
- The whole process of AS400 API from zero to one
- PHP converts two-dimensional array elements into key value pairs
猜你喜欢

Sitge joined the opengauss open source community to jointly promote the ecological development of the database industry

Lecun, a Turing Award winner, pointed out that the future of AI lies in self-learning, and the company has embarked on the journey

With regard to the white box test, you have to master these skills~

Complete software development process

测试必备工具—Postman实战教程

45 year old programmer tells you: why do programmers want to change jobs? It's too true

亲测有效,快速创建JMeter桌面快捷方式

1500w播放下还藏着什么热点?B站2个未来趋势你不得错过

Upstream and downstream in software development

Fast understanding of forward proxy and reverse proxy
随机推荐
What will Web3 bring in the future?
那些一门心思研究自动化测试的人,后来怎样了?
Using recyclerreview to show banner is very simple
Thinking about business and investment
PHP array splicing MySQL in statement
数据探索电商平台用户行为流失分析
zabbix如何配置告警短信?(预警短信通知设置流程)
7-2 拼题A打卡奖励 dp
Laravel event & Monitoring
小程序中实现excel数据的批量导入
3500字归纳总结:一名合格的软件测试工程师需要掌握的技能大全
[无线通信基础-15]:图解移动通信技术与应用发展-3- 数字通信2G GSM、CDMA、3G WDCMA/CDMA200/TD-SCDMA、4G LTE、5G NR概述
What are the functions of soil microorganisms in microbial detection?
[simulation] 922 Sort Array By Parity II
软件测试的可持续发展,必须要学会敲代码?
org. redisson. client. Redisresponsetimeoutexception: redis server response timeout (3000 ms) error resolution
[fundamentals of wireless communication-15]: illustrated mobile communication technology and application development-3-overview of digital communication 2G GSM, CDMA, 3G wdcma/cdma200/td-scdma, 4G LTE
After working for 6 years, let's take stock of the golden rule of the workplace where workers mix up
laravel Carbon 时间处理类使用
AS400 大廠面試