qtcore.rst 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // @snippet q_arg
  2. This function takes a type (or a type string) and a value of that type
  3. and returns an internal object that can be passed to
  4. :meth:`QMetaObject.invokeMethod`. See also Q_RETURN_ARG().
  5. // @snippet q_arg
  6. // @snippet q_return_arg
  7. This macro takes a type (or a type string) a value of which is then
  8. returned by :meth:`QMetaObject.invokeMethod`. See also Q_ARG().
  9. // @snippet q_return_arg
  10. // @snippet qlocale-system
  11. Returns a QLocale object initialized to the system locale.
  12. The system locale may use system-specific sources for locale data, where
  13. available, otherwise falling back on QLocale's built-in database entry for the
  14. language, script and territory the system reports.
  15. For example, on Windows, this locale will use the decimal/grouping characters and
  16. date/time formats specified in the system configuration panel.
  17. .. note:: Qt for Python on macOS will not reflect the user's region and language
  18. preferences though QLocale::system(), but will instead reflect the
  19. environment variables POSIX uses to specify locale, similar to Python's
  20. locale module. If the system locale cannot be determined, which can be
  21. due to none of the variables 'LC_ALL', 'LC_CTYPE', 'LANG' or 'LANGUAGE'
  22. being set by your environment, then the default POSIX locale or
  23. 'C' locale is returned.
  24. See also c().
  25. // @snippet qlocale-system
  26. // @snippet qabstractitemmodel-createindex
  27. Creates a model index for the given row and column with the internal pointer
  28. ptr. When using a :class:`QSortFilterProxyModel`, its indexes have their own
  29. internal pointer. It is not advisable to access this internal pointer outside
  30. of the model. Use the ``data()`` function instead.
  31. This function provides a consistent interface that model subclasses must use to
  32. create model indexes.
  33. .. warning:: Because of some Qt/Python integration rules, the ``ptr`` argument does
  34. not get the reference incremented during the QModelIndex life time.
  35. So it is necessary to keep the object used on ``ptr`` argument alive
  36. during the whole process. Do not destroy the object if you are not
  37. sure about that.
  38. // @snippet qabstractitemmodel-createindex
  39. // @snippet qobject-findChild
  40. To find the child of a certain :class:`QObject`, the first argument of this
  41. function should be the child's type, and the second the name of the child:
  42. ::
  43. ...
  44. parent = QWidget()
  45. ...
  46. # The first argument must be the child type
  47. child1 = parent.findChild(QPushButton, "child_button")
  48. child2 = parent.findChild(QWidget, "child_widget")
  49. // @snippet qobject-findChild
  50. // @snippet qcoreapplication-init
  51. Constructs a Qt kernel application. Kernel applications are applications
  52. without a graphical user interface. These type of applications are used
  53. at the console or as server processes.
  54. The *args* argument is processed by the application, and made available
  55. in a more convenient form by the :meth:`~PySide6.QtCore.QCoreApplication.arguments()`
  56. method.
  57. // @snippet qcoreapplication-init
  58. // @snippet qsettings-value
  59. Custom overload that adds an optional named parameter to the function ``value()``
  60. to automatically cast the type that is being returned by the function.
  61. An example of this situation could be an ini file that contains
  62. the value of a one-element list::
  63. settings.setValue('var', ['a'])
  64. The the ini file will be::
  65. [General]
  66. var=a # we cannot know that this is a list!
  67. Once we read it, we could specify if we want
  68. the default behavior, a str, or to cast the output
  69. to a list.
  70. settings.value('var') # Will get "a"
  71. settings.value('var', type=list) # Will get ["a"]
  72. // @snippet qsettings-value
  73. // @snippet qmessagelogger
  74. In Python, the :class:`QMessageLogger` is useful to connect an existing logging
  75. setup that uses the Python logging module to the Qt logging system. This allows
  76. you to leverage Qt's logging infrastructure while still using the familiar
  77. Python logging API.
  78. Example::
  79. import logging
  80. from PySide6.QtCore import QMessageLogger
  81. class LogHandler(logging.Handler):
  82. def emit(self, record: logging.LogRecord):
  83. if record.levelno == logging.DEBUG:
  84. logger = QMessageLogger(record.filename, record.lineno, record.funcName)
  85. logger.debug(record.message)
  86. logging.basicConfig(handlers=[LogHandler()])
  87. logging.debug("Test debug message")
  88. // @snippet qmessagelogger
  89. // @snippet qrangemodel-numpy-constructor
  90. The function takes one-dimensional or two-dimensional numpy arrays of various
  91. integer or float types to populate an editable QRangeModel.
  92. // @snippet qrangemodel-numpy-constructor
  93. // @snippet qrangemodel-sequence-constructor
  94. The function takes a sequence of of data to populate a read-only QRangeModel.
  95. // @snippet qrangemodel-sequence-constructor