TextField.qml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (C) 2017 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. // Qt-Security score:significant reason:default
  4. import QtQuick
  5. import QtQuick.Controls.impl
  6. import QtQuick.Templates as T
  7. T.TextField {
  8. id: control
  9. implicitWidth: implicitBackgroundWidth + leftInset + rightInset
  10. || Math.max(contentWidth, placeholder.implicitWidth) + leftPadding + rightPadding
  11. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  12. contentHeight + topPadding + bottomPadding,
  13. placeholder.implicitHeight + topPadding + bottomPadding)
  14. padding: 6
  15. leftPadding: padding + 4
  16. color: control.palette.text
  17. selectionColor: control.palette.highlight
  18. selectedTextColor: control.palette.highlightedText
  19. placeholderTextColor: control.palette.placeholderText
  20. verticalAlignment: TextInput.AlignVCenter
  21. PlaceholderText {
  22. id: placeholder
  23. x: control.leftPadding
  24. y: control.topPadding
  25. width: control.width - (control.leftPadding + control.rightPadding)
  26. height: control.height - (control.topPadding + control.bottomPadding)
  27. text: control.placeholderText
  28. font: control.font
  29. color: control.placeholderTextColor
  30. verticalAlignment: control.verticalAlignment
  31. visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter)
  32. elide: Text.ElideRight
  33. renderType: control.renderType
  34. }
  35. background: Rectangle {
  36. implicitWidth: 200
  37. implicitHeight: 40
  38. border.width: control.activeFocus ? 2 : 1
  39. color: control.palette.base
  40. border.color: {
  41. if (control.activeFocus)
  42. return control.palette.highlight
  43. else if (Qt.styleHints.accessibility.contrastPreference !== Qt.HighContrast)
  44. return control.palette.mid
  45. else
  46. return Color.blend(control.palette.text, control.palette.base,
  47. control.enabled ? 0.0 : 0.5)
  48. }
  49. }
  50. }