exe 依赖添加

This commit is contained in:
Neo
2026-01-27 23:19:54 +08:00
parent 8b1200383e
commit ba00654ac5
3443 changed files with 754994 additions and 51 deletions

View File

@@ -0,0 +1,127 @@
// @snippet q_arg
This function takes a type (or a type string) and a value of that type
and returns an internal object that can be passed to
:meth:`QMetaObject.invokeMethod`. See also Q_RETURN_ARG().
// @snippet q_arg
// @snippet q_return_arg
This macro takes a type (or a type string) a value of which is then
returned by :meth:`QMetaObject.invokeMethod`. See also Q_ARG().
// @snippet q_return_arg
// @snippet qlocale-system
Returns a QLocale object initialized to the system locale.
The system locale may use system-specific sources for locale data, where
available, otherwise falling back on QLocale's built-in database entry for the
language, script and territory the system reports.
For example, on Windows, this locale will use the decimal/grouping characters and
date/time formats specified in the system configuration panel.
.. note:: Qt for Python on macOS will not reflect the user's region and language
preferences though QLocale::system(), but will instead reflect the
environment variables POSIX uses to specify locale, similar to Python's
locale module. If the system locale cannot be determined, which can be
due to none of the variables 'LC_ALL', 'LC_CTYPE', 'LANG' or 'LANGUAGE'
being set by your environment, then the default POSIX locale or
'C' locale is returned.
See also c().
// @snippet qlocale-system
// @snippet qabstractitemmodel-createindex
Creates a model index for the given row and column with the internal pointer
ptr. When using a :class:`QSortFilterProxyModel`, its indexes have their own
internal pointer. It is not advisable to access this internal pointer outside
of the model. Use the ``data()`` function instead.
This function provides a consistent interface that model subclasses must use to
create model indexes.
.. warning:: Because of some Qt/Python integration rules, the ``ptr`` argument does
not get the reference incremented during the QModelIndex life time.
So it is necessary to keep the object used on ``ptr`` argument alive
during the whole process. Do not destroy the object if you are not
sure about that.
// @snippet qabstractitemmodel-createindex
// @snippet qobject-findChild
To find the child of a certain :class:`QObject`, the first argument of this
function should be the child's type, and the second the name of the child:
::
...
parent = QWidget()
...
# The first argument must be the child type
child1 = parent.findChild(QPushButton, "child_button")
child2 = parent.findChild(QWidget, "child_widget")
// @snippet qobject-findChild
// @snippet qcoreapplication-init
Constructs a Qt kernel application. Kernel applications are applications
without a graphical user interface. These type of applications are used
at the console or as server processes.
The *args* argument is processed by the application, and made available
in a more convenient form by the :meth:`~PySide6.QtCore.QCoreApplication.arguments()`
method.
// @snippet qcoreapplication-init
// @snippet qsettings-value
Custom overload that adds an optional named parameter to the function ``value()``
to automatically cast the type that is being returned by the function.
An example of this situation could be an ini file that contains
the value of a one-element list::
settings.setValue('var', ['a'])
The the ini file will be::
[General]
var=a # we cannot know that this is a list!
Once we read it, we could specify if we want
the default behavior, a str, or to cast the output
to a list.
settings.value('var') # Will get "a"
settings.value('var', type=list) # Will get ["a"]
// @snippet qsettings-value
// @snippet qmessagelogger
In Python, the :class:`QMessageLogger` is useful to connect an existing logging
setup that uses the Python logging module to the Qt logging system. This allows
you to leverage Qt's logging infrastructure while still using the familiar
Python logging API.
Example::
import logging
from PySide6.QtCore import QMessageLogger
class LogHandler(logging.Handler):
def emit(self, record: logging.LogRecord):
if record.levelno == logging.DEBUG:
logger = QMessageLogger(record.filename, record.lineno, record.funcName)
logger.debug(record.message)
logging.basicConfig(handlers=[LogHandler()])
logging.debug("Test debug message")
// @snippet qmessagelogger
// @snippet qrangemodel-numpy-constructor
The function takes one-dimensional or two-dimensional numpy arrays of various
integer or float types to populate an editable QRangeModel.
// @snippet qrangemodel-numpy-constructor
// @snippet qrangemodel-sequence-constructor
The function takes a sequence of of data to populate a read-only QRangeModel.
// @snippet qrangemodel-sequence-constructor

View File

@@ -0,0 +1,152 @@
// @snippet qmlregistersingletoninstance
.. py:function:: qmlRegisterSingletonInstance(pytype: type,\
uri: str,\
versionMajor: int,\
versionMinor: int,\
typeName: str,\
instanceObject: object) -> int
:param type pytype: Python class
:param str uri: uri to use while importing the component in QML
:param int versionMajor: major version
:param int versionMinor: minor version
:param str typeName: name exposed to QML
:param object instanceObject: singleton object to be registered
:return: int (the QML type id)
This function registers a singleton Python object *instanceObject*, with a
particular *uri* and *typeName*. Its version is a combination of *versionMajor*
and *versionMinor*. Use this function to register an object of the given type
*pytype* as a singleton type.
// @snippet qmlregistersingletoninstance
// @snippet qmlregistersingletontype_qobject_nocallback
.. py:function:: qmlRegisterSingletonType(pytype: type, uri: str, versionMajor: int, versionMinor: int, typeName: str) -> int
:param type pytype: Python class
:param str uri: uri to use while importing the component in QML
:param int versionMajor: major version
:param int versionMinor: minor version
:param str typeName: name exposed to QML
:return: int (the QML type id)
This function registers a Python type as a singleton in the QML system.
Alternatively, the :ref:`QmlSingleton` decorator can be used.
// @snippet qmlregistersingletontype_qobject_nocallback
// @snippet qmlregistersingletontype_qobject_callback
.. py:function:: qmlRegisterSingletonType(pytype: type, uri: str, versionMajor: int, versionMinor: int, typeName: str, callback: object) -> int
:param type pytype: Python class
:param str uri: uri to use while importing the component in QML
:param int versionMajor: major version
:param int versionMinor: minor version
:param str typeName: name exposed to QML
:param object callback: Python callable (to handle Python type)
:return: int (the QML type id)
This function registers a Python type as a singleton in the QML system using
the provided callback (which gets a QQmlEngine as a parameter) to generate the
singleton.
// @snippet qmlregistersingletontype_qobject_callback
// @snippet qmlregistersingletontype_qjsvalue
.. py:function:: qmlRegisterSingletonType(uri: str, versionMajor: int, versionMinor: int, typeName: str, callback: object) -> int
:param str uri: uri to use while importing the component in QML
:param int versionMajor: major version
:param int versionMinor: minor version
:param str typeName: name exposed to QML
:param object callback: Python callable (to handle QJSValue)
:return: int (the QML type id)
This function registers a QJSValue as a singleton in the QML system using the
provided callback (which gets a QQmlEngine as a parameter) to generate the
singleton.
// @snippet qmlregistersingletontype_qjsvalue
// @snippet qmlregistertype
.. py:function:: qmlRegisterType(pytype: type, uri: str, versionMajor: int, versionMinor: int, qmlName: str) -> int
:param type pytype: Python class
:param str uri: uri to use while importing the component in QML
:param int versionMajor: major version
:param int versionMinor: minor version
:param str qmlName: name exposed to QML
:return: int (the QML type id)
This function registers the Python *type* in the QML system with the name
*qmlName*, in the library imported from *uri* having the version number
composed from *versionMajor* and *versionMinor*. For example, this registers a
Python class 'MySliderItem' as a QML type named 'Slider' for version '1.0' of a
module called 'com.mycompany.qmlcomponents':
::
qmlRegisterType(MySliderItem, "com.mycompany.qmlcomponents", 1, 0, "Slider")
Once this is registered, the type can be used in QML by importing the specified
module name and version number:
::
import com.mycompany.qmlcomponents 1.0
Slider { ... }
Note that it's perfectly reasonable for a library to register types to older
versions than the actual version of the library. Indeed, it is normal for the
new library to allow QML written to previous versions to continue to work, even
if more advanced versions of some of its types are available.
// @snippet qmlregistertype
// @snippet qmlregisteruncreatabletype
.. py:function:: qmlRegisterUncreatableType(pytype: type, uri: str, versionMajor: int, versionMinor: int, qmlName: str, noCreationReason: str) -> int
:param type pytype: Python class
:param str uri: uri to use while importing the component in QML
:param int versionMajor: major version
:param int versionMinor: minor version
:param str qmlName: name exposed to QML
:param str noCreationReason: Error message shown when trying to create the QML type
:return: int (the QML type id)
This function registers the Python *type* in the QML system as an uncreatable
type with the name *qmlName*, in the library imported from *uri* having the
version number composed from *versionMajor* and *versionMinor*, showing
*noCreationReason* as an error message when creating the type is attempted. For
example, this registers a Python class 'MySliderItem' as a QML type named
'Slider' for version '1.0' of a module called 'com.mycompany.qmlcomponents':
::
qmlRegisterUncreatableType(MySliderItem, "com.mycompany.qmlcomponents", 1, 0, "Slider", "Slider cannot be created.")
Note that it's perfectly reasonable for a library to register types to older
versions than the actual version of the library. Indeed, it is normal for the
new library to allow QML written to previous versions to continue to work, even
if more advanced versions of some of its types are available.
Alternatively, the :ref:`QmlUncreatable` decorator can be used.
// @snippet qmlregisteruncreatabletype
// @snippet qqmlengine-singletoninstance-qmltypeid
Returns the instance of a singleton type that was registered under qmlTypeId.
For ``QObject``-derived singleton types, the ``QObject`` instance is returned,
otherwise a ``QJSValue`` or ``None``.
It is recommended to store the QML type id, e.g. as a static member in the
singleton class. The lookup via qmlTypeId() is costly.
// @snippet qqmlengine-singletoninstance-qmltypeid
// @snippet qqmlengine-singletoninstance-typename
Returns the instance of a singleton type named typeName from the module specified
by uri. For ``QObject``-derived singleton types, the ``QObject`` instance is
returned, otherwise a ``QJSValue`` or ``None``.
This method can be used as an alternative to calling qmlTypeId followed by the
id based overload of singletonInstance. This is convenient when one only needs
to do a one time setup of a singleton; if repeated access to the singleton is
required, caching its typeId will allow faster subsequent access via the
type-id based overload.
// @snippet qqmlengine-singletoninstance-typename

View File

@@ -0,0 +1,62 @@
// @snippet quick_test_main_documentation
Sets up the entry point for a Qt Quick Test application.
The ``name`` argument uniquely identifies this set of tests.
``sys.argv`` should be passed to the ``argv`` argument to ensure
propagation of the command line arguments.
.. note:: The function assumes that your test sources are in the current
directory, unless the ``QUICK_TEST_SOURCE_DIR`` environment
variable is set or a directory is passed in ``dir``.
The following snippet demonstrates the use of this function:
.. code-block:: Python
import sys
from PySide6.QtQuickTest import QUICK_TEST_MAIN
ex = QUICK_TEST_MAIN("example", sys.argv)
sys.exit(ex)
// @snippet quick_test_main_documentation
// @snippet quick_test_main_with_setup_documentation
Sets up the entry point for a Qt Quick Test application.
The ``name`` argument uniquely identifies this set of tests.
``sys.argv`` should be passed to the ``argv`` argument to ensure
propagation of the command line arguments.
This function is identical to ``QUICK_TEST_MAIN()``, except that it takes an
additional argument ``setup``, the type of a ``QObject``-derived
class which will be instantiated. With this class, it is possible to define
additional setup code to execute before running the QML test.
The following snippet demonstrates the use of this function:
.. code-block:: Python
import sys
from PySide6.QtQuickTest import QUICK_TEST_MAIN_WITH_SETUP
class CustomTestSetup(QObject):
def __init__(self, parent=None):
super().__init__(parent)
@Slot(QQmlEngine)
def qmlEngineAvailable(self, qmlEngine):
pass
ex = QUICK_TEST_MAIN_WITH_SETUP("qquicktestsetup", CustomTestSetup, sys.argv)
sys.exit(ex)
.. note:: The function assumes that your test sources are in the current
directory, unless the ``QUICK_TEST_SOURCE_DIR`` environment
variable is set or a directory is passed in ``dir``.
// @snippet quick_test_main_with_setup_documentation

View File

@@ -0,0 +1,68 @@
// @snippet quiloader-registercustomwidget
Registers a Python created custom widget to QUiLoader, so it can be recognized
when loading a `.ui` file. The custom widget type is passed via the
``customWidgetType`` argument. This is needed when you want to override a
virtual method of some widget in the interface, since duck punching will not
work with widgets created by QUiLoader based on the contents of the `.ui` file.
(Remember that
`duck punching virtual methods is an invitation for your own demise! <https://doc.qt.io/qtforpython/shiboken6/wordsofadvice.html#duck-punching-and-virtual-methods>`_)
Let's see an obvious example. If you want to create a new widget it's probable you'll end up
overriding :class:`~PySide6.QtGui.QWidget`'s :meth:`~PySide6.QtGui.QWidget.paintEvent` method.
.. code-block:: python
class Circle(QWidget):
def paintEvent(self, event):
with QPainter(self) as painter:
painter.setPen(self.pen)
painter.setBrush(QBrush(self.color))
painter.drawEllipse(event.rect().center(), 20, 20)
# ...
loader = QUiLoader()
loader.registerCustomWidget(Circle)
circle = loader.load('circle.ui')
circle.show()
# ...
// @snippet quiloader-registercustomwidget
// @snippet loaduitype
.. currentmodule:: PySide6.QtUiTools
loadUiType
***********
.. py:function:: loadUiType(uifile: str) -> tuple(object, object)
:param str uifile: The name of the `.ui` file
:return: tuple(object, object)
This function generates and loads a `.ui` file at runtime, and it returns
a `tuple` containing the reference to the Python class, and the base class.
We recommend not to use this approach as the workflow should be to generate a Python file
from the `.ui` file, and then import and load it to use it, but we do understand that
there are some corner cases when such functionality is required.
The internal process relies on `uic` being in the PATH.
The `pyside6-uic` wrapper uses a shipped `uic` that is located in the
`site-packages/PySide6/uic`, so PATH needs to be updated to use that if there
is no `uic` in the system.
A simple use case is::
from PySide6.QtUiTools import loadUiType
generated_class, base_class = loadUiType("themewidget.ui")
# the values will be:
# (<class '__main__.Ui_ThemeWidgetForm'>, <class 'PySide6.QtWidgets.QWidget'>)
widget = base_class()
form = generated_class()
form.setupUi(widget)
# form.a_widget_member.a_method_of_member()
widget.show()
// @snippet loaduitype

View File

@@ -0,0 +1,75 @@
// @snippet qwebenginepage-async-note
.. note:: We guarantee that the ``resultCallback`` is always called, but it
might be done during page destruction. When ``QWebEnginePage``
is deleted, the callback is triggered with an invalid value and it
is not safe to use the corresponding ``QWebEnginePage``,
``QWebEngineFrame``, or ``QWebEngineView`` instance inside it.
// @snippet qwebenginepage-async-note
// @snippet qwebenginepage-findtext
Finds the specified string, ``subString``, in the page, using the given
``options``. The ``findTextFinished()`` signal is emitted when a string search
is completed.
To clear the search highlight, just pass an empty string.
The ``resultCallback`` must take a ``QWebEngineFindTextResult`` parameter.
// @snippet qwebenginepage-findtext
// @snippet qwebenginepage-tohtml
Asynchronous method to retrieve the page's content as HTML, enclosed in HTML
and BODY tags. Upon successful completion, ``resultCallback`` is called with
the page's content.
// @snippet qwebenginepage-tohtml
// @snippet qwebenginepage-toplaintext
Asynchronous method to retrieve the page's content converted to plain text,
completely stripped of all HTML formatting.
Upon successful completion, ``resultCallback`` is called with the page's content.
// @snippet qwebenginepage-toplaintext
// @snippet qwebenginepage-runjavascript
Runs the JavaScript code contained in ``scriptSource`` script on this frame,
without checking whether the DOM of the page has been constructed.
To avoid conflicts with other scripts executed on the page, the world in which
the script is run is specified by ``worldId``. The world ID values are the same
as provided by ``QWebEngineScript.ScriptWorldId``, and between 0 and 256. If
you leave out the world ID, the script is run in the ``MainWorld`` (0).
When the script has been executed, the callable ``resultCallback`` is called
with the result of the last executed statement.
Only plain data can be returned from JavaScript as the result value.
.. note:: Do not execute lengthy routines in the callback function, because
it might block the rendering of the web engine page.
// @snippet qwebenginepage-runjavascript
// @snippet qwebenginepage-printtopdf
Renders the current content of the page into a PDF document and returns a byte
array containing the PDF data as parameter to ``resultCallback``.
The page size and orientation of the produced PDF document are taken from the
values specified in ``layout``, while the range of pages printed is taken from
``ranges`` with the default being printing all pages.
.. note:: The ``QWebEnginePage.WebAction.Stop`` web action can be used to
interrupt this operation.
// @snippet qwebenginepage-printtopdf
// @snippet qwebenginepage-findframebyname
Returns the frame with the given ``name``. If there are multiple frames with
the same name, which one is returned is arbitrary. If no frame was found,
returns ``None``.
// @snippet qwebenginepage-findframebyname
// @snippet qwebengineframe-printtopdf
Renders the current content of the frame into a PDF document and returns a byte
array containing the PDF data as parameter to ``resultCallback``. Printing uses
a page size of A4, portrait layout, and includes the full range of pages.
.. note:: The ``QWebEnginePage.WebAction.Stop`` web action can be used to
interrupt this operation.
// @snippet qwebengineframe-printtopdf