NIconButton: added native tooltip handling
This commit is contained in:
parent
275c2ae8ba
commit
9e0bb64d07
4 changed files with 18 additions and 17 deletions
|
|
@ -83,8 +83,8 @@ Variants {
|
||||||
|
|
||||||
NIconButton {
|
NIconButton {
|
||||||
id: demoPanelToggle
|
id: demoPanelToggle
|
||||||
|
|
||||||
icon: "experiment"
|
icon: "experiment"
|
||||||
|
tooltipText: "Open demo panel"
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
onClicked: function () {
|
onClicked: function () {
|
||||||
demoPanel.isLoaded = !demoPanel.isLoaded
|
demoPanel.isLoaded = !demoPanel.isLoaded
|
||||||
|
|
@ -93,8 +93,8 @@ Variants {
|
||||||
|
|
||||||
NIconButton {
|
NIconButton {
|
||||||
id: sidePanelToggle
|
id: sidePanelToggle
|
||||||
|
|
||||||
icon: "widgets"
|
icon: "widgets"
|
||||||
|
tooltipText: "Open side panel"
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
onClicked: function () {
|
onClicked: function () {
|
||||||
// Map this button's center to the screen and open the side panel below it
|
// Map this button's center to the screen and open the side panel below it
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ NPill {
|
||||||
|
|
||||||
if (testMode) {
|
if (testMode) {
|
||||||
lines.push("Time left: " + Time.formatVagueHumanReadableDuration(12345))
|
lines.push("Time left: " + Time.formatVagueHumanReadableDuration(12345))
|
||||||
return lines.join("\n");
|
return lines.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!root.isReady) {
|
if (!root.isReady) {
|
||||||
|
|
|
||||||
|
|
@ -52,18 +52,6 @@ NLoader {
|
||||||
NIconButton {
|
NIconButton {
|
||||||
id: myIconButton
|
id: myIconButton
|
||||||
icon: "refresh"
|
icon: "refresh"
|
||||||
onEntered: function () {
|
|
||||||
myTooltip.show()
|
|
||||||
}
|
|
||||||
onExited: function () {
|
|
||||||
myTooltip.hide()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NTooltip {
|
|
||||||
id: myTooltip
|
|
||||||
target: myIconButton
|
|
||||||
positionAbove: false
|
|
||||||
text: "Hello world"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NDivider {
|
NDivider {
|
||||||
|
|
@ -74,9 +62,8 @@ NLoader {
|
||||||
// NToggle
|
// NToggle
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
spacing: Style.marginLarge * scaling
|
spacing: Style.marginLarge * scaling
|
||||||
uniformCellSizes: true
|
|
||||||
NText {
|
NText {
|
||||||
text: "NToggle + NTooltip"
|
text: "NToggle"
|
||||||
color: Colors.accentSecondary
|
color: Colors.accentSecondary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ Rectangle {
|
||||||
property real sizeMultiplier: 0.8
|
property real sizeMultiplier: 0.8
|
||||||
property real size: Style.baseWidgetSize * sizeMultiplier * scaling
|
property real size: Style.baseWidgetSize * sizeMultiplier * scaling
|
||||||
property string icon
|
property string icon
|
||||||
|
property string tooltipText
|
||||||
property bool enabled: true
|
property bool enabled: true
|
||||||
property bool hovering: false
|
property bool hovering: false
|
||||||
property var onEntered: function () {}
|
property var onEntered: function () {}
|
||||||
|
|
@ -37,16 +38,29 @@ Rectangle {
|
||||||
opacity: root.enabled ? Style.opacityFull : Style.opacityMedium
|
opacity: root.enabled ? Style.opacityFull : Style.opacityMedium
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NTooltip {
|
||||||
|
id: tooltip
|
||||||
|
target: root
|
||||||
|
positionAbove: false
|
||||||
|
text: root.tooltipText
|
||||||
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onEntered: {
|
onEntered: {
|
||||||
hovering = true
|
hovering = true
|
||||||
|
if (tooltipText) {
|
||||||
|
tooltip.show()
|
||||||
|
}
|
||||||
root.onEntered()
|
root.onEntered()
|
||||||
}
|
}
|
||||||
onExited: {
|
onExited: {
|
||||||
hovering = false
|
hovering = false
|
||||||
|
if (tooltipText) {
|
||||||
|
tooltip.hide()
|
||||||
|
}
|
||||||
root.onExited()
|
root.onExited()
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue