AnimationsPage.qml 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import Felgo 4.0
  2. import QtQuick 2.12
  3. import QtQuick.Controls
  4. import QtMultimedia
  5. import "../common"
  6. import "../controls"
  7. AppPage {
  8. id: root
  9. title: "日志"
  10. rightBarItem: IconButtonBarItem {
  11. iconType: IconType.paintbrush
  12. onClicked: {
  13. audio.play()
  14. }
  15. }
  16. MediaPlayer{
  17. id: audio
  18. audioOutput: AudioOutput{}
  19. source: Qt.resolvedUrl("../../assets/mp3/button.mp3")
  20. }
  21. //property string message:""
  22. AppFlickable {
  23. id: scroll
  24. anchors.fill: parent
  25. contentHeight: content.height
  26. bottomMargin: nativeUtils.safeAreaInsets.bottom
  27. // 接收并显示日志消息
  28. // Connections {
  29. // target: logger
  30. // onLogMessage: {
  31. // logTextArea.text += message + "\n"
  32. // console.log("logTextArea:",logTextArea.contentHeight)
  33. // if(logTextArea.contentHeight>5000){
  34. // logTextArea.clear()
  35. // }
  36. // }
  37. // }
  38. Column {
  39. id: content
  40. width: parent.width
  41. TextArea {
  42. id: logTextArea
  43. readOnly: true
  44. wrapMode: TextArea.WrapAtWordBoundaryOrAnywhere
  45. width: parent.width
  46. text: "日志"
  47. function scrollToLatestLine() {
  48. // 获取TextArea的内容高度
  49. var contentHeight = logTextArea.contentHeight;
  50. // 计算滚动位置,使视图滚动到最底部
  51. var scrollPosition = contentHeight - scroll.height;
  52. // 使用动画效果来平滑滚动
  53. scroll.contentY = scrollPosition;
  54. }
  55. onTextChanged: {
  56. // 当文本发生变化时,调用滚动函数以将视图滚动到最新行
  57. scrollToLatestLine();
  58. }
  59. }
  60. }
  61. }
  62. //}
  63. }