added border hover effect for textarea

This commit is contained in:
ronoaer 2023-09-25 22:16:59 +08:00
parent a6d660e708
commit 8b08a5bee0

View file

@ -30,6 +30,7 @@ Item {
property string backgroundColor: "#1c1d21" property string backgroundColor: "#1c1d21"
property string backgroundDisabledColor: "transparent" property string backgroundDisabledColor: "transparent"
property string bgBorderHoveredColor: "#494B50"
implicitWidth: content.implicitWidth implicitWidth: content.implicitWidth
implicitHeight: content.implicitHeight implicitHeight: content.implicitHeight
@ -44,7 +45,7 @@ Item {
Layout.preferredHeight: input.implicitHeight Layout.preferredHeight: input.implicitHeight
color: root.enabled ? root.backgroundColor : root.backgroundDisabledColor color: root.enabled ? root.backgroundColor : root.backgroundDisabledColor
radius: 16 radius: 16
border.color: textField.focus ? root.borderFocusedColor : root.borderColor border.color: getBackgroundBorderColor(root.borderColor)
border.width: 1 border.width: 1
Behavior on border.color { Behavior on border.color {
@ -102,12 +103,17 @@ Item {
anchors.fill: parent anchors.fill: parent
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
onClicked: contextMenu.open() onClicked: contextMenu.open()
enabled: true
} }
ContextMenuType { ContextMenuType {
id: contextMenu id: contextMenu
textObj: textField textObj: textField
} }
onFocusChanged: {
backgroud.border.color = getBackgroundBorderColor(root.borderColor)
}
} }
} }
@ -149,11 +155,28 @@ Item {
MouseArea { MouseArea {
anchors.fill: root anchors.fill: root
cursorShape: Qt.PointingHandCursor cursorShape: Qt.IBeamCursor
hoverEnabled: true
onPressed: function(mouse) { onPressed: function(mouse) {
textField.forceActiveFocus() textField.forceActiveFocus()
mouse.accepted = false mouse.accepted = false
backgroud.border.color = getBackgroundBorderColor(root.borderColor)
}
onEntered: {
backgroud.border.color = getBackgroundBorderColor(bgBorderHoveredColor)
}
onExited: {
backgroud.border.color = getBackgroundBorderColor(root.borderColor)
} }
} }
function getBackgroundBorderColor(noneFocusedColor) {
return textField.focus ? root.borderFocusedColor : noneFocusedColor
}
} }