main.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright (C) 2022 The Qt Company Ltd.
  2. # SPDX-License-Identifier: LicenseRef-Qt-Commercial
  3. import sys
  4. from pathlib import Path
  5. from PySide6.QtCore import QObject, Slot
  6. from PySide6.QtGui import QGuiApplication
  7. from PySide6.QtQml import QQmlApplicationEngine, QmlElement
  8. from PySide6.QtQuickControls2 import QQuickStyle
  9. import style_rc
  10. # To be used on the @QmlElement decorator
  11. # (QML_IMPORT_MINOR_VERSION is optional)
  12. QML_IMPORT_NAME = "io.qt.textproperties"
  13. QML_IMPORT_MAJOR_VERSION = 1
  14. @QmlElement
  15. class Bridge(QObject):
  16. @Slot(str, result=str)
  17. def getColor(self, s):
  18. if s.lower() == "red":
  19. return "#ef9a9a"
  20. elif s.lower() == "green":
  21. return "#a5d6a7"
  22. elif s.lower() == "blue":
  23. return "#90caf9"
  24. else:
  25. return "white"
  26. @Slot(float, result=int)
  27. def getSize(self, s):
  28. size = int(s * 34)
  29. if size <= 0:
  30. return 1
  31. else:
  32. return size
  33. @Slot(str, result=bool)
  34. def getItalic(self, s):
  35. if s.lower() == "italic":
  36. return True
  37. else:
  38. return False
  39. @Slot(str, result=bool)
  40. def getBold(self, s):
  41. if s.lower() == "bold":
  42. return True
  43. else:
  44. return False
  45. @Slot(str, result=bool)
  46. def getUnderline(self, s):
  47. if s.lower() == "underline":
  48. return True
  49. else:
  50. return False
  51. if __name__ == '__main__':
  52. app = QGuiApplication(sys.argv)
  53. QQuickStyle.setStyle("Material")
  54. engine = QQmlApplicationEngine()
  55. # Get the path of the current directory, and then add the name
  56. # of the QML file, to load it.
  57. qml_file = 'view.qml'
  58. engine.load(qml_file)
  59. if not engine.rootObjects():
  60. sys.exit(-1)
  61. sys.exit(app.exec())