### Setup Started Signal Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qthelp/qhelpenginecore This signal is emitted when the help engine's setup process begins. ```APIDOC setupStarted() ``` -------------------------------- ### C++ Example: Initialize QApplication and Install QTranslator Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qtranslator This C++ example demonstrates the typical setup for an internationalized Qt application. It shows how to create a `QApplication`, load a translation file (`.qm`) using `QTranslator::load()`, and then install it globally with `QCoreApplication::installTranslator()`. The example also includes a `QPushButton` with text translated using `QCoreApplication::translate()`. ```C++ # int main(int argc, char *argv[]) # { # QApplication app(argc, argv); # QTranslator translator; # // look up e.g. :/i18n/myapp_de.qm # if (translator.load(QLocale(), QLatin1String("myapp"), QLatin1String("_"), QLatin1String(":/i18n"))) # QCoreApplication::installTranslator(&translator); # QPushButton hello(QCoreApplication::translate("main", "Hello world!")); # hello.resize(100, 30); # hello.show(); # return app.exec(); # } ``` -------------------------------- ### C++ QWizard Start Page Configuration Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtwidgets/qwizardpage Sets the initial page that the `QWizard` will display when it is launched. In this example, the wizard begins with the `Page_Intro`, guiding the user from the start. ```C++ setStartId(Page_Intro); ``` -------------------------------- ### C++ Example: Initialize and Configure QTechnique Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qt3drender/qtechnique Demonstrates how to create a QTechnique instance, add render passes, set graphics API filters (OpenGL 3.1 Core Profile), add a filter key, and define a parameter. This example illustrates the basic setup for a rendering technique. ```C++ QTechnique *gl3Technique = new QTechnique(); // Create the render passes QRenderPass *firstPass = new QRenderPass(); QRenderPass *secondPass = new QRenderPass(); // Add the passes to the technique gl3Technique->addRenderPass(firstPass); gl3Technique->addRenderPass(secondPass); // Set the targeted GL version for the technique gl3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL); gl3Technique->graphicsApiFilter()->setMajorVersion(3); gl3Technique->graphicsApiFilter()->setMinorVersion(1); gl3Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::CoreProfile); // Create a FilterKey QFilterKey *filterKey = new QFilterKey(); filterKey->setName(QStringLiteral("name")); fitlerKey->setValue(QStringLiteral("zFillPass")); // Add the FilterKey to the Technique gl3Technique->addFilterKey(filterKey); // Create a QParameter QParameter *colorParameter = new QParameter(QStringLiteral("color"), QColor::fromRgbF(0.0f, 0.0f, 1.0f, 1.0f)); // Add parameter to technique gl3Technique->addParameter(colorParameter); ``` -------------------------------- ### QBluetoothServer Class Methods and Service Registration Example Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtbluetooth/qbluetoothserver Detailed API documentation for the QBluetoothServer class methods, including their signatures, descriptions, parameters, return values, and related functions. This snippet also provides a C++ code example demonstrating the intricate setup of QBluetoothServiceInfo for service registration, specifically for an RFCOMM server. ```APIDOC Class: QBluetoothServer Method: __init__(Protocol, parent: QObject = None) Description: Constructs a bluetooth server with parent and serverType. Method: close() Description: Closes and resets the listening socket. Any already established QBluetoothSocket continues to operate and must be separately close(). Method: error() -> Error Description: Returns the last error of the QBluetoothServer. Method: hasPendingConnections() -> bool Description: Returns true if a connection is pending, otherwise false. Method: isListening() -> bool Description: Returns true if the server is listening for incoming connections, otherwise false. Method: listen(address: QBluetoothAddress = QBluetoothAddress(), port: int = 0) -> bool Description: Start listening for incoming connections to address on port. address must be a local Bluetooth adapter address and port must be larger than zero and not be taken already by another Bluetooth server object. It is recommended to avoid setting a port number to enable the system to automatically choose a port. Returns true if the operation succeeded and the server is listening for incoming connections, otherwise returns false. If the server object is already listening for incoming connections this function always returns false. See also: isListening(), newConnection. Method: listen(QBluetoothUuid, serviceName: Optional[str] = '') -> QBluetoothServiceInfo Description: Convenience function for registering an SPP service with uuid and serviceName. Because this function already registers the service, the QBluetoothServiceInfo object which is returned can not be changed any more. To shutdown the server later on it is required to call unregisterService() and close() on this server object. Returns a registered QBluetoothServiceInfo instance if successful otherwise an invalid QBluetoothServiceInfo. This function always assumes that the default Bluetooth adapter should be used. If the server object is already listening for incoming connections this function returns an invalid QBluetoothServiceInfo. See also: isListening(), newConnection, listen(). ``` ```C++ QBluetoothServiceInfo serviceInfo; serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, serviceName); QBluetoothServiceInfo::Sequence browseSequence; browseSequence << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::ServiceClassUuid::PublicBrowseGroup)); serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList, browseSequence); QBluetoothServiceInfo::Sequence profileSequence; QBluetoothServiceInfo::Sequence classId; classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::ServiceClassUuid::SerialPort)); classId << QVariant::fromValue(quint16(0x100)); profileSequence.append(QVariant::fromValue(classId)); serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList, profileSequence); classId.clear(); //Android requires custom uuid to be set as service class classId << QVariant::fromValue(uuid); classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::ServiceClassUuid::SerialPort)); serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId); serviceInfo.setServiceUuid(uuid); QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::ProtocolUuid::L2cap)); if (d->serverType == QBluetoothServiceInfo::L2capProtocol) protocol << QVariant::fromValue(serverPort()); protocolDescriptorList.append(QVariant::fromValue(protocol)); protocol.clear(); protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::ProtocolUuid::Rfcomm)) << QVariant::fromValue(quint8(serverPort())); protocolDescriptorList.append(QVariant::fromValue(protocol)); serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); bool result = serviceInfo.registerService(); ``` -------------------------------- ### Complete Minimal Q3DBars Graph Example Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtdatavisualization/q3dbars This comprehensive C++ example demonstrates the full setup and display of a basic Q3DBars graph. It includes application initialization, clearing window flags, setting axis ranges, creating and adding a data series, and finally showing the graph, providing a runnable example for a minimal 3D bar chart. ```C++ #include int main(int argc, char **argv) { qputenv("QSG_RHI_BACKEND", "opengl"); QGuiApplication app(argc, argv); Q3DBars bars; bars.setFlags(bars.flags() ^ Qt::FramelessWindowHint); bars.rowAxis()->setRange(0, 4); bars.columnAxis()->setRange(0, 4); QBar3DSeries *series = new QBar3DSeries; QBarDataRow *data = new QBarDataRow; *data << 1.0f << 3.0f << 7.5f << 5.0f << 2.2f; series->dataProxy()->addRow(data); bars.addSeries(series); bars.show(); return app.exec(); } ``` -------------------------------- ### C++ OAuth 2.0 Authorization Flow Setup Example Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtnetworkauth/qoauthurischemereplyhandler A comprehensive C++ example demonstrating the setup of an OAuth 2.0 authorization code flow. It includes configuration for authorization and access token URLs, client identifiers, scopes, and connecting signals for browser interaction and token acquisition, showcasing both HTTP server and URI scheme reply handlers. ```C++ # This code needs porting to Python. # // Copyright (C) 2024 The Qt Company Ltd. # // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause # #include # #include # #include # #include # #include # #include # #include # #include # using namespace Qt::StringLiterals; # class HttpServerExample : public QObject # { # Q_OBJECT # public: # void setup() # { # #! [httpserver-oauth-setup] # m_oauth.setAuthorizationUrl(QUrl("https://some.authorization.service/v3/authorize"_L1)); # m_oauth.setAccessTokenUrl(QUrl("https://some.authorization.service/v3/access_token"_L1)); ``` -------------------------------- ### Basic QGraphicsView Initialization Example Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtwidgets/qgraphicsview Demonstrates the conceptual steps to create a QGraphicsScene and then initialize a QGraphicsView to display its contents. This snippet illustrates the fundamental setup for visualizing a scene within a PyQt6 application, mirroring common Qt C++ examples. ```Python # QGraphicsScene scene; # scene.addText("Hello, world!"); # QGraphicsView view(&scene); ``` -------------------------------- ### Main Application Setup for a Trivial QWizard Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtwidgets/qwizard This `main` function initializes a QApplication, which is essential for any Qt application. It then optionally sets up a system-specific translator. A QWizard instance is created, and the previously defined introduction, registration, and conclusion pages are added to it. Finally, the wizard's window title is set, the wizard is displayed, and the application's event loop is started. ```C++ int main(int argc, char *argv[]) { QApplication app(argc, argv); #ifndef QT_NO_TRANSLATION QString translatorFileName = QLatin1String("qtbase_"); translatorFileName += QLocale::system().name(); QTranslator *translator = new QTranslator(&app); if (translator->load(translatorFileName, QLibraryInfo::path(QLibraryInfo::TranslationsPath))) app.installTranslator(translator); #endif QWizard wizard; wizard.addPage(createIntroPage()); wizard.addPage(createRegistrationPage()); wizard.addPage(createConclusionPage()); wizard.setWindowTitle("Trivial Wizard"); wizard.show(); return app.exec(); } ``` -------------------------------- ### Initialize and Display QQuickView with QML Source Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtquick/qquickview Demonstrates the fundamental steps to initialize a QQuickView instance, set its QML source file using `QUrl::fromLocalFile`, and display the view. This example uses `QGuiApplication` for the application context and is suitable for basic QML application setup. ```C++ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQuickView *view = new QQuickView; view->setSource(QUrl::fromLocalFile("myqmlfile.qml")); view->show(); return app.exec(); } ``` -------------------------------- ### Complete Minimal Q3DSurface Graph Example (C++) Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtdatavisualization/q3dsurface This comprehensive C++ example demonstrates the full process of creating and displaying a basic 3D surface graph using Q3DSurface. It includes application setup, Q3DSurface initialization, data preparation using QSurfaceDataArray and QSurfaceDataRow, series creation with QSurface3DSeries, and finally, displaying the interactive 3D graph. ```C++ #include int main(int argc, char **argv) { qputenv("QSG_RHI_BACKEND", "opengl"); QGuiApplication app(argc, argv); Q3DSurface surface; surface.setFlags(surface.flags() ^ Qt::FramelessWindowHint); QSurfaceDataArray *data = new QSurfaceDataArray; QSurfaceDataRow *dataRow1 = new QSurfaceDataRow; QSurfaceDataRow *dataRow2 = new QSurfaceDataRow; *dataRow1 << QVector3D(0.0f, 0.1f, 0.5f) << QVector3D(1.0f, 0.5f, 0.5f); *dataRow2 << QVector3D(0.0f, 1.8f, 1.0f) << QVector3D(1.0f, 1.2f, 1.0f); *data << dataRow1 << dataRow2; QSurface3DSeries *series = new QSurface3DSeries; series->dataProxy()->resetArray(data); surface.addSeries(series); surface.show(); return app.exec(); } ``` -------------------------------- ### Build and Install PyQt6 with Manual Make Steps Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/installation These commands allow for a more granular build process. `sip-build --no-make` prepares the build without executing the `make` command, which is then run separately, followed by `make install` to complete the installation. This is useful for custom build environments or debugging. ```Shell sip-build --no-make make make install ``` -------------------------------- ### Display Video with QVideoWidget and QMediaPlayer (C++) Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtmultimediawidgets/qvideowidget Example demonstrating how to initialize a QMediaPlayer, set its source, attach a QVideoWidget for video output, and play the media. This snippet illustrates the basic setup for video playback in a Qt C++ application. ```C++ # player = new QMediaPlayer; # player->setSource(QUrl("http://example.com/myclip1.mp4")); # videoWidget = new QVideoWidget; # player->setVideoOutput(videoWidget); # videoWidget->show(); # player->play(); ``` -------------------------------- ### Perform a Simple Network Download with QNetworkAccessManager Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtnetwork/qnetworkaccessmanager This example demonstrates how to initiate a basic HTTP GET request using QNetworkAccessManager. It shows the creation of a manager, connecting its 'finished' signal to a slot for handling the reply, and executing a GET request for a specified URL. This highlights the asynchronous nature of the API. ```C++ # QNetworkAccessManager *manager = new QNetworkAccessManager(this); # connect(manager, &QNetworkAccessManager::finished, # this, &MyClass::replyFinished); # manager->get(QNetworkRequest(QUrl("http://qt-project.org"))); ``` -------------------------------- ### Basic Usage Example for QNetworkRequestFactory Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtnetwork/qnetworkrequestfactory This C++ example demonstrates the fundamental steps for using QNetworkRequestFactory: instantiation with a base URL, setting a bearer token common to all requests, and then issuing GET requests for different paths using the `createRequest` method. It shows how to construct URLs like `https://example.com/v1/models`. ```C++ # // Instantiate a factory somewhere suitable in the application # QNetworkRequestFactory api{{"https://example.com/v1"_L1}}; # // Set bearer token # api.setBearerToken("my_token"); # // Issue requests (reply handling omitted for brevity) # manager.get(api.createRequest("models"_L1)); // https://example.com/v1/models # // The conventional leading '/' for the path can be used as well # manager.get(api.createRequest("/models"_L1)); // https://example.com/v1/models ``` -------------------------------- ### Initialize QQmlApplicationEngine for QML Application in C++ Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtqml/qqmlapplicationengine This C++ example demonstrates the basic setup for a QML application using `QQmlApplicationEngine`. It initializes a `QGuiApplication` and creates an engine instance to load a specified QML file, serving as the entry point for a C++/QML hybrid application. ```C++ #include #include int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine("main.qml"); return app.exec(); } ``` -------------------------------- ### Install PyQt6 using sip-install Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/installation This command installs PyQt6 using the `sip-install` tool. It's the primary method for building and installing PyQt6 from source after unpacking the sdist. ```Shell sip-install ``` -------------------------------- ### Basic XML Writing with QXmlStreamWriter (C++ Example) Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qxmlstreamwriter Illustrates the fundamental steps to write a simple XML document using QXmlStreamWriter. This C++ example, found within PyQt6 documentation, demonstrates starting a document, setting auto-formatting, writing an element with an attribute, writing a text element, and ending the document. In a PyQt6 Python context, similar methods would be called on a QXmlStreamWriter instance. ```C++ # QXmlStreamWriter stream(&output); # stream.setAutoFormatting(true); # stream.writeStartDocument(); # stream.writeStartElement("bookmark"); # stream.writeAttribute("href", "http://qt-project.org/"); # stream.writeTextElement("title", "Qt Project"); # stream.writeEndElement(); // bookmark # stream.writeEndDocument(); ``` -------------------------------- ### Start External Program with QProcess Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qprocess This code snippet illustrates how to launch an external application using PyQt6's QProcess. It demonstrates setting the program path and passing command-line arguments, specifically for running an analog clock example with a 'fusion' style. ```Python # QObject *parent; # QString program = "./path/to/Qt/examples/widgets/analogclock"; # QStringList arguments; # arguments << "-style" << "fusion"; # QProcess *myProcess = new QProcess(parent); # myProcess->start(program, arguments); ``` -------------------------------- ### Setup Help Engine Data Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qthelp/qhelpenginecore Sets up the help engine by processing information from the collection file and returns true if successful; otherwise false. Calling this function forces immediate initialization. Note: `qsqlite4.dll` must be deployed with the application as the help system uses the sqlite driver. ```APIDOC setupData() -> bool ``` -------------------------------- ### Example: Piping Processes with QProcess (C++) Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qprocess Demonstrates how to achieve a shell-like pipe (`command1 | command2`) using two `QProcess` objects in C++. It shows how to set up the output of one process to feed into the input of another before starting both processes. ```cpp # command1 | command2 QProcess process1; QProcess process2; process1.setStandardOutputProcess(&process2); process1.start("command1"); process2.start("command2"); ``` -------------------------------- ### Define AudioInputExample Class and Setup Method Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtmultimedia/qaudiosink Defines a C++ class `AudioInputExample` inheriting from `QObject`, including necessary Qt multimedia headers, public slots for state handling, and private members for file and audio source management. It also shows the beginning of a `setup` method. ```C++ #include #include #include #include #include #include "qaudiodevice.h" #include "qaudiosource.h" #include "qaudiooutput.h" #include "qaudiodecoder.h" #include "qmediaplayer.h" #include "qmediadevices.h" class AudioInputExample : public QObject { Q_OBJECT public: void setup(); public Q_SLOTS: void stopRecording(); void handleStateChanged(QAudio::State newState); private: QFile destinationFile; // Class member QAudioSource* audio; // Class member }; void AudioInputExample::setup() { ``` -------------------------------- ### Get Start Y-Coordinate (y1) Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qlinef Returns the y-coordinate of the line’s start point. ```APIDOC y1() -> float ``` -------------------------------- ### PyQt6 Audio Output Setup and Playback Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtmultimedia/qaudiosink This snippet demonstrates how to set up audio output using `QAudioSink` to play audio from a raw file. It opens the source file, configures the audio format, checks if the format is supported by the default output device, and then starts audio playback. ```C++ void AudioOutputExample::setup() { sourceFile.setFileName("/tmp/test.raw"); sourceFile.open(QIODevice::ReadOnly); QAudioFormat format; // Set up the format, eg. format.setSampleRate(8000); format.setChannelCount(1); format.setSampleFormat(QAudioFormat::UInt8); QAudioDevice info(QAudioDevice::defaultOutputDevice()); if (!info.isFormatSupported(format)) { qWarning() << "Raw audio format not supported by backend, cannot play audio."; return; } audio = new QAudioSink(format, this); connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); audio->start(&sourceFile); } ``` -------------------------------- ### Get Start X-Coordinate (x1) Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qlinef Returns the x-coordinate of the line’s start point. ```APIDOC x1() -> float ``` -------------------------------- ### Main Application Entry Point for QElapsedTimer Examples (C++) Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qelapsedtimer The main function initializes a `QCoreApplication` and orchestrates the execution of various `QElapsedTimer` example functions. It serves as the entry point for demonstrating the different timing scenarios within a complete C++ program context. ```C++ int main(int argc, char **argv) { QCoreApplication app(argc, argv); startExample(); restartExample(); executeSlowOperations(5); executeOperationsForTime(5); } ``` -------------------------------- ### Basic QMediaPlayer C++ Usage Example Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtmultimedia/qmediaplayer Illustrates the fundamental steps to initialize a QMediaPlayer instance, configure audio output, connect signals for position changes, set a local media source, adjust volume, and initiate playback using C++. ```C++ player = new QMediaPlayer; audioOutput = new QAudioOutput; player->setAudioOutput(audioOutput); connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64))); player->setSource(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3")); audioOutput->setVolume(50); player->play(); ``` -------------------------------- ### QTimer Class API Reference and Usage Examples Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qtimer Provides a complete API reference for the PyQt6 QTimer class, detailing its constructor, methods for controlling timer behavior (start, stop, interval, single-shot), and the `timeout` signal. Includes a usage example demonstrating how to set the interval and start the timer. ```APIDOC QTimer Class: Description: A timer class that provides a high-level interface for timers. Supports millisecond resolution and a maximum interval of ±24 days. For higher precision or longer intervals, consider QChronoTimer. Alternatives: - QChronoTimer: Supports larger interval range (±292 years) and higher precision (std::chrono::nanoseconds). - timerEvent(): Reimplement in QObject subclasses. - QBasicTimer: Lightweight value-class wrapping a timer ID. Use start() and stop(). - Direct Timer IDs: Use startTimer() and killTimer(). Less convenient than QBasicTimer. Methods: __init__(parent: QObject = None) Constructs a timer with the given parent. id() -> int Returns a Qt::TimerId representing the timer ID if the timer is running; otherwise returns Qt::TimerId::Invalid. interval() -> int Returns the current timer interval. isActive() -> bool Returns true if the timer is running; otherwise returns false. isSingleShot() -> bool TODO remainingTime() -> int TODO setInterval(value: int) Sets the timer interval to value milliseconds. setSingleShot(singleShot: bool) Sets whether the timer is a single-shot timer. setTimerType(type: TimerType) Sets the timer type. @staticmethod singleShot(msec: int, slot: PYQT_SLOT) TODO @staticmethod singleShot(msec: int, type: TimerType, slot: PYQT_SLOT) TODO start() Starts or restarts the timer with the timeout specified in interval(). If the timer is already running, it will be stopped and restarted. start(msec: int) Starts or restarts the timer with a timeout interval of msec milliseconds. If the timer is already running, it will be stopped and restarted. Equivalent to setInterval(msec) followed by start(). stop() Stops the timer. timerEvent(event: QTimerEvent) TODO timerId() -> int Returns the ID of the timer if the timer is running; otherwise returns -1. timerType() -> TimerType Returns the current timer type. Signals: timeout() Emitted when the timer times out. ``` ```Python timer.setInterval(msec) timer.start() ``` -------------------------------- ### Get All Top-Level Widgets and Show Hidden Example Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtwidgets/qapplication Returns a list of all top-level widgets (windows) in the application. Note that some of these widgets may be hidden, for example, a tooltip not currently shown. The included C++ example demonstrates how to iterate through this list and show any hidden top-level widgets. ```APIDOC @staticmethod topLevelWidgets() -> list[QWidget] ``` ```C++ void showAllHiddenTopLevelWidgets() { const QWidgetList topLevelWidgets = QApplication::topLevelWidgets(); for (QWidget *widget : topLevelWidgets) { if (widget->isHidden()) widget->show(); } } ``` -------------------------------- ### Install PyQt-builder for PyQt6 Commercial and Source Builds Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/installation This command installs the PyQt-builder package, a crucial tool for both bundling custom Qt installations with commercial PyQt6 and for building PyQt6 from source. It extends SIP's build system, providing enhanced configuration capabilities. ```bash pip install PyQt-builder ``` -------------------------------- ### Get Start Drag Time Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtwidgets/qapplication Returns the time in milliseconds after which a drag operation is started. This static method provides the global time delay for initiating drag events. See also setStartDragTime(). ```APIDOC @staticmethod startDragTime() -> int ``` -------------------------------- ### Example: Basic QMediaRecorder Usage with QMediaCaptureSession Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtmultimedia/qmediarecorder Demonstrates how to set up a QMediaRecorder with a QMediaCaptureSession and an QAudioInput to record audio to a local file. It shows the steps to connect inputs, set output location, quality, and initiate recording. ```python # QMediaCaptureSession session; # QAudioInput audioInput; # session.setAudioInput(&input); # QMediaRecorder recorder; # session.setMediaRecorder(&recorder); # recorder.setQuality(QMediaRecorder::HighQuality); # recorder.setOutputLocation(QUrl::fromLocalFile("test.mp3")); # recorder.record(); ``` -------------------------------- ### Install PyQt6 GPL Version via pip Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/installation This command installs the GPL version of PyQt6 using pip. It automatically downloads the appropriate wheel from PyPI based on your platform and Python version. This is the recommended and most straightforward installation method. ```Python pip install PyQt6 ``` -------------------------------- ### Get Selection Start Position Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtgui/qtextcursor This method returns the absolute integer position of the start of the current selection. If no text is selected, it returns the current position of the cursor. ```APIDOC selectionStart() -> int Returns: The absolute integer position of the start of the selection, or the cursor's current position if no selection exists. ``` -------------------------------- ### __init__ Method Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qthelp/qhelpenginecore Constructs a new core help engine with a parent. The help engine uses the information stored in the collectionFile to provide help. If the collection file does not exist yet, it will be created. ```APIDOC __init__(collectionFile: Optional[str], parent: QObject = None) Constructs a new core help engine with a *parent*. The help engine uses the information stored in the *collectionFile* to provide help. If the collection file does not exist yet, it’ll be created. ``` -------------------------------- ### Main Application Entry Point for QElapsedTimer Examples in C++ Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qelapsedtimer Provides the `main` function, which serves as the entry point for the application. It initializes the Qt Core application context and orchestrates calls to the various `QElapsedTimer` demonstration functions, showcasing their usage in a complete program. ```cpp int main(int argc, char **argv) { QCoreApplication app(argc, argv); startExample(); restartExample(); executeSlowOperations(5); executeOperationsForTime(5); } ``` -------------------------------- ### Install Scene Event Filter Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtwidgets/qgraphicsitem Installs an event filter for this item on *filterItem*, causing all events for this item to first pass through *filterItem*’s `sceneEventFilter()` function. To filter another item’s events, install this item as an event filter for the other item. Example: `...` ```APIDOC installSceneEventFilter(filterItem: QGraphicsItem) filterItem: The QGraphicsItem to install the event filter on. Installs an event filter for this item on filterItem, causing all events for this item to first pass through filterItem’s sceneEventFilter() function. To filter another item’s events, install this item as an event filter for the other item. ``` -------------------------------- ### Qt C++ QMediaCaptureSession Recording Example Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtmultimedia/qscreencapture Illustrates a conceptual setup for QMediaCaptureSession with audio input and QMediaRecorder to record media. This snippet, though commented out and in C++ syntax, provides context for how screen capture might integrate into a media recording workflow within a Qt application. ```C++ # QMediaCaptureSession session; # QAudioInput audioInput; # session.setAudioInput(&input); # QMediaRecorder recorder; # session.setMediaRecorder(&recorder); # recorder.setQuality(QMediaRecorder::HighQuality); # recorder.setOutputLocation(QUrl::fromLocalFile("test.mp3")); # recorder.record(); ``` -------------------------------- ### Get Program Path (PyQt6 QProcess) Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qprocess Returns the program the process was last started with. ```APIDOC program() → str Returns the program the process was last started with. ``` -------------------------------- ### QPainter begin() Method API Reference Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtgui/qpainter API documentation for the `begin()` method of QPainter, including its parameters, return type, and important warnings regarding usage. ```APIDOC begin(QPaintDevice) → bool Begins painting the paint device and returns true if successful; otherwise returns false. ``` -------------------------------- ### Example Usage of QLayer in Qt3D Scene Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qt3drender/qlayer Demonstrates how to create and apply a QLayer to an entity within a Qt3D scene, and how to filter it using QLayerFilter in the FrameGraph. This example shows the necessary includes and the setup for both the scene and the FrameGraph. ```C++ #include #include #include #include #include // Scene Qt3DCore::QEntity *rootEntity = new Qt3DCore::Qt3DCore::QEntity; Qt3DCore::QEntity *renderableEntity = new Qt3DCore::Qt3DCore::QEntity(rootEntity); Qt3DRender::QGeometryRenderer *geometryRenderer = new Qt3DCore::QGeometryRenderer(renderableEntity); Qt3DRender::QLayer *layer1 = new Qt3DCore::QLayer(renderableEntity); layer1->setRecursive(true); renderableEntity->addComponent(geometryRenderer); renderableEntity->addComponent(layer1); ... // FrameGraph Qt3DRender::QViewport *viewport = new Qt3DRender::QViewport; Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(viewport); layerFilter->addLayer(layer1); ... ``` -------------------------------- ### Set Up and Start QAudioSource Recording Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtmultimedia/qaudiosource Demonstrates how to configure `QAudioSource` for recording, including setting the destination file, defining audio format (`QAudioFormat`), checking format support, instantiating `QAudioSource`, connecting state change signals, and starting the recording to a file for a fixed duration. ```C++ # { # destinationFile.setFileName("/tmp/test.raw"); # destinationFile.open( QIODevice::WriteOnly | QIODevice::Truncate ); # QAudioFormat format; # // Set up the desired format, for example: # format.setSampleRate(8000); # format.setChannelCount(1); # format.setSampleFormat(QAudioFormat::UInt8); # QAudioDevice info = QMediaDevices::defaultAudioInput(); # if (!info.isFormatSupported(format)) { # qWarning() << "Default format not supported, trying to use the nearest."; # } # audio = new QAudioSource(format, this); # connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); # QTimer::singleShot(3000, this, SLOT(stopRecording())); # audio->start(&destinationFile); # // Records audio for 3000ms # } ``` -------------------------------- ### PyQt6 Audio Input Setup and Recording Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtmultimedia/qaudiosink This snippet demonstrates how to set up audio input using `QAudioSource` to record audio to a file. It configures the audio format (sample rate, channel count, sample format), checks for device support, and starts recording for a specified duration (3000ms). ```C++ destinationFile.setFileName("/tmp/test.raw"); destinationFile.open( QIODevice::WriteOnly | QIODevice::Truncate ); QAudioFormat format; // Set up the desired format, for example: format.setSampleRate(8000); format.setChannelCount(1); format.setSampleFormat(QAudioFormat::UInt8); QAudioDevice info = QMediaDevices::defaultAudioInput(); if (!info.isFormatSupported(format)) { qWarning() << "Default format not supported, trying to use the nearest."; } audio = new QAudioSource(format, this); connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); QTimer::singleShot(3000, this, SLOT(stopRecording())); audio->start(&destinationFile); // Records audio for 3000ms ``` -------------------------------- ### Get Start Drag Distance Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtwidgets/qapplication Returns the minimum distance a mouse must be moved before a drag operation is started. This static method provides the global threshold for initiating drag events. See also setStartDragDistance(). ```APIDOC @staticmethod startDragDistance() -> int ``` -------------------------------- ### Setup Finished Signal Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qthelp/qhelpenginecore This signal is emitted when the help engine's setup process is complete. ```APIDOC setupFinished() ``` -------------------------------- ### Animate QObject Geometry with QPropertyAnimation (C++) Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qpropertyanimation This C++ example demonstrates how to create and configure a QPropertyAnimation to animate the 'geometry' property of a QWidget. It sets the animation duration, defines the start and end QRect values for the geometry, and then starts the animation. ```C++ QPropertyAnimation *animation = new QPropertyAnimation(myWidget, "geometry"); animation->setDuration(10000); animation->setStartValue(QRect(0, 0, 100, 30)); animation->setEndValue(QRect(250, 250, 100, 30)); animation->start(); ``` -------------------------------- ### Basic Vulkan-Capable QWindow Example Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtgui/qvulkaninstance This example demonstrates how to set up a basic `QWindow` for Vulkan rendering. It shows initializing `QVulkanInstance`, handling expose events to set up Vulkan devices and swapchains, and continuous rendering. ```cpp class VulkanWindow : public QWindow { public: VulkanWindow() { setSurfaceType(VulkanSurface); } void exposeEvent(QExposeEvent *) { if (isExposed()) { if (!m_initialized) { m_initialized = true; // initialize device, swapchain, etc. QVulkanInstance *inst = vulkanInstance(); QVulkanFunctions *f = inst->functions(); uint32_t devCount = 0; f->vkEnumeratePhysicalDevices(inst->vkInstance(), &devCount, nullptr); // ... // build the first frame render(); } } } bool event(QEvent *e) { if (e->type() == QEvent::UpdateRequest) render(); return QWindow::event(e); } void render() { // ... requestUpdate(); // render continuously } private: bool m_initialized = false; }; int main(int argc, char **argv) { QGuiApplication app(argc, argv); QVulkanInstance inst; if (!inst.create()) { qWarning("Vulkan not available"); return 1; } VulkanWindow window; } ``` -------------------------------- ### Issue GET Request with QRestAccessManager using Callbacks Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtnetwork/qrestaccessmanager Illustrates sending a GET request with `QRestAccessManager` using a callback function. This example shows both a lambda function and a member function as callbacks, which are invoked upon completion of the request. ```C++ // With lambda manager->get(request, this, [this](QRestReply &reply) { if (reply.isSuccess()) { // ... } }); // With member function manager->get(request, this, &MyClass::handleFinished); ``` -------------------------------- ### Get Elapsed Milliseconds Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qelapsedtimer Returns the number of milliseconds since this QElapsedTimer was last started. Calling this function on an invalid QElapsedTimer results in undefined behavior. Related functions include start(), restart(), hasExpired(), isValid(), and invalidate(). ```APIDOC elapsed() -> int ``` -------------------------------- ### __init__(list[str]) Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtgui/qguiapplication Initializes the QApplication instance. Further details are marked as TODO. ```APIDOC __init__(list[str]) TODO ``` -------------------------------- ### Get Start and End Offsets of Captured Groups Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qregularexpressionmatch Demonstrates how to retrieve the starting and ending character offsets of a specific captured group within the subject string using `capturedStart()` and `capturedEnd()`. This is useful for precise substring extraction or manipulation. ```cpp QRegularExpression re("abc(\\d+)def"); QRegularExpressionMatch match = re.match("XYZabc123defXYZ"); if (match.hasMatch()) { int startOffset = match.capturedStart(1); // startOffset == 6 int endOffset = match.capturedEnd(1); // endOffset == 9 // ... } ``` -------------------------------- ### Initialize QImageCapture with QCamera and QMediaCaptureSession Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtmultimedia/qimagecapture This C++ code snippet demonstrates the essential steps to set up a QImageCapture instance. It shows how to create a QMediaCaptureSession, associate it with a QCamera, configure a QVideoWidget for preview output, and finally, instantiate and link QImageCapture before starting the camera. ```C++ QMediaCaptureSession captureSession; camera = new QCamera; captureSession.setCamera(camera); QVideoWidget *preview = new QVideoWidget(); preview->show(); captureSession.setVideoOutput(preview); imageCapture = new QImageCapture(camera); captureSession.setImageCapture(imageCapture); camera->start(); ``` -------------------------------- ### Main Application Entry Point for QWizard (C++) Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtwidgets/qwizard The main function initializes the QApplication, optionally loads system translations, creates a QWizard instance, adds the predefined introduction, registration, and conclusion pages, sets the wizard's window title, displays it, and starts the application's event loop. ```C++ int main(int argc, char *argv[]) { QApplication app(argc, argv); #ifndef QT_NO_TRANSLATION QString translatorFileName = QLatin1String("qtbase_"); translatorFileName += QLocale::system().name(); QTranslator *translator = new QTranslator(&app); if (translator->load(translatorFileName, QLibraryInfo::path(QLibraryInfo::TranslationsPath))) app.installTranslator(translator); #endif QWizard wizard; wizard.addPage(createIntroPage()); wizard.addPage(createRegistrationPage()); wizard.addPage(createConclusionPage()); wizard.setWindowTitle("Trivial Wizard"); wizard.show(); return app.exec(); } ``` -------------------------------- ### Get Start and End Offsets of Captured Groups Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qregularexpressionmatch This snippet shows how to determine the character offsets of a specific captured group within the input string. The `capturedStart()` and `capturedEnd()` methods provide the zero-based start and end indices of the captured substring. ```C++ QRegularExpression re("abc(\\d+)def"); QRegularExpressionMatch match = re.match("XYZabc123defXYZ"); if (match.hasMatch()) { int startOffset = match.capturedStart(1); // startOffset == 6 int endOffset = match.capturedEnd(1); // endOffset == 9 // ... } ``` -------------------------------- ### Get QVideoFrame Start Time Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtmultimedia/qvideoframe Returns the presentation time (in microseconds) when the frame is scheduled to be displayed. An invalid time is indicated by -1. ```APIDOC startTime() -> int Description: Returns the presentation time (in microseconds) when the frame should be displayed. An invalid time is represented as -1. Returns: int (The presentation time in microseconds.) ``` -------------------------------- ### PyQt6 Installation and Runtime Command Line Options Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/genindex This snippet details various command-line options used for configuring PyQt6 installation, DBus integration, and designer/QML plugin behavior. ```APIDOC --confirm-license --dbus --license-dir --no-dbus-python --no-designer-plugin --no-qml-plugin --no-tools --qt-shared ``` -------------------------------- ### PyQt6 QPageSetupDialog Class API Reference Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtprintsupport/qpagesetupdialog Detailed API documentation for the QPageSetupDialog class from PyQt6.QtPrintSupport, outlining its inheritance from QDialog, its primary function as a page setup configuration dialog, and a comprehensive list of its methods with their signatures and descriptions. ```APIDOC QPageSetupDialog: Inherits: PyQt6.QtPrintSupport.QPageSetupDialog (from QDialog) Description: The QPageSetupDialog class provides a configuration dialog for the page-related options on a printer. On Windows and macOS, it uses native dialogs, with noted limitations for custom paper sizes and margins. See also: QPrinter, QPrintDialog Methods: - name: __init__ parameters: - name: parent type: QWidget default: None description: Constructs a page setup dialog that configures a default-constructed QPrinter with parent as the parent widget. notes: See also printer(). - name: __init__ parameters: - name: printer type: QPrinter - name: parent type: QWidget default: None description: Constructs a page setup dialog that configures printer with parent as the parent widget. - name: done parameters: - name: arg type: int description: TODO - name: exec returns: int description: TODO - name: open description: TODO - name: open parameters: - name: arg type: PYQT_SLOT description: TODO - name: printer returns: QPrinter description: Returns the printer that was passed to the QPageSetupDialog constructor. - name: setVisible parameters: - name: visible type: bool description: TODO ``` -------------------------------- ### View sip-install Command Line Options Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/installation This command displays all available command-line options for the `sip-install` tool, providing detailed information on its various functionalities and configurable parameters. ```Shell sip-install -h ``` -------------------------------- ### Demonstrate QSystemSemaphore acquire and release operations Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qsystemsemaphore This example illustrates the basic usage of QSystemSemaphore, showing how to create a semaphore with an initial resource count and then acquire and release resources. It demonstrates the counting behavior of the semaphore. ```Python # QSystemSemaphore sem("market", 3, QSystemSemaphore::Create); # // resources available == 3 # sem.acquire(); // resources available == 2 # sem.acquire(); // resources available == 1 # sem.acquire(); // resources available == 0 # sem.release(); // resources available == 1 # sem.release(2); // resources available == 3 ``` -------------------------------- ### Get Elapsed Nanoseconds Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qelapsedtimer Returns the number of nanoseconds since this QElapsedTimer was last started. Calling this function on an invalid QElapsedTimer results in undefined behavior. On platforms without nanosecond resolution, the best available estimate is returned. See also start(), restart(), hasExpired(), and invalidate(). ```APIDOC nsecsElapsed() -> int ``` -------------------------------- ### C++ QML Image Provider Registration and Application Setup Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtquick/qquickimageprovider Sets up the main application in C++, initializing `QGuiApplication` and `QQuickView`. It registers an instance of `ColorImageProvider` with the QML engine under the identifier 'colors', allowing QML to access it. Finally, it loads a QML file ('imageprovider-example.qml') and displays the view. ```cpp int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQuickView view; QQmlEngine *engine = view.engine(); engine->addImageProvider(QLatin1String("colors"), new ColorImageProvider); view.setSource(QUrl::fromLocalFile(QStringLiteral("imageprovider-example.qml"))); view.show(); return app.exec(); } ``` -------------------------------- ### Get QStyle Name Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtwidgets/qstyle Returns the name of the current style. This can be useful for identifying the active style, for example, 'Fusion', 'Windows', or 'macOS'. ```APIDOC name() -> str Returns: str - The name of the style. ``` -------------------------------- ### Build PyQt6 from Source with pip Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/installation This command demonstrates how to build PyQt6 from source using pip. It includes verbose output (`-v`) and specifies configuration settings such as confirming the license and providing the path to `qmake`. This method is typically used when a pre-built wheel is unavailable or specific build customizations are required. ```Shell pip -v install --config-settings --confirm-license= --config-settings --qmake=/path/to/qmake PyQt6 ``` -------------------------------- ### Restart Timer and Get Elapsed Time Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qelapsedtimer Restarts the timer and returns the number of milliseconds elapsed since the previous start. This function combines obtaining elapsed time with elapsed() and restarting with start() into a single, efficient operation. Calling this function on an invalid QElapsedTimer results in undefined behavior. ```APIDOC restart() -> int ``` -------------------------------- ### Get Unit Vector Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qlinef Returns the unit vector for this line, i.e a line starting at the same point as this line with a length of 1.0, provided the line is non-null. ```APIDOC unitVector() -> QLineF ``` -------------------------------- ### QPainter begin() Method Error Examples (C++) Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtgui/qpainter C++ code examples illustrating common errors and impossible scenarios when calling the `QPainter::begin()` method. ```C++ # painter->begin(0); // impossible - paint device cannot be 0 # QPixmap image(0, 0); # painter->begin(&image); // impossible - image.isNull() == true; # painter->begin(myWidget); # painter2->begin(myWidget); // impossible - only one painter at a time ``` -------------------------------- ### PyQt6 QObject: Basic installEventFilter Call Example Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qobject A simple C++ example demonstrating the syntax for calling the `installEventFilter` method on a monitored object. ```C++ monitoredObj->installEventFilter(filterObj); ``` -------------------------------- ### Get Available Writing Systems (PyQt6) Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtgui/qfontdatabase Returns a sorted list of all writing systems available on the system, derived from installed font information. ```APIDOC @staticmethod writingSystems() → list[[WritingSystem]] Returns: A sorted list of available writing systems. ``` -------------------------------- ### Retrieve Captured Substring Offsets in QRegularExpression Source: https://www.riverbankcomputing.com/static/Docs/PyQt6/module_index.html/api/qtcore/qregularexpression Demonstrates how to get the start and end character offsets of a captured substring within the subject string using match.capturedStart() and match.capturedEnd(). ```cpp QRegularExpression re("abc(\\d+)def"); QRegularExpressionMatch match = re.match("XYZabc123defXYZ"); if (match.hasMatch()) { int startOffset = match.capturedStart(1); // startOffset == 6 int endOffset = match.capturedEnd(1); // endOffset == 9 // ... } ```