Skip to content

QMessageHandler#

superqt.utils.QMessageHandler #

A context manager to intercept messages from Qt.

Parameters:

Name Type Description Default
logger Logger

If provided, intercepted messages will be logged with logger at the corresponding python log level, by default None

None

Attributes:

Name Type Description
records list of tuple

Captured messages. This is a 3-tuple of: (log_level: int, message: str, context: dict)

Examples:

>>> handler = QMessageHandler()
>>> handler.install()  # now all Qt output will be available at mh.records
>>> with QMessageHandler() as handler:  # temporarily install
...     ...
>>> logger = logging.getLogger(__name__)
>>> with QMessageHandler(logger):  # re-reoute Qt messages to a python logger.
...    ...

__enter__() #

Enter a context with this handler installed.

install() #

Install this handler (override the current QtMessageHandler).

uninstall() #

Uninstall this handler, restoring the previous handler.