diff options
Diffstat (limited to 'examples/widgetbinding')
-rw-r--r-- | examples/widgetbinding/CMakeLists.txt | 37 | ||||
-rw-r--r-- | examples/widgetbinding/dialog.py | 3 | ||||
-rw-r--r-- | examples/widgetbinding/doc/widgetbinding.md (renamed from examples/widgetbinding/README.md) | 8 | ||||
-rw-r--r-- | examples/widgetbinding/doc/widgetbinding.pyproject | 10 | ||||
-rw-r--r-- | examples/widgetbinding/wigglywidget.cpp | 12 |
5 files changed, 50 insertions, 20 deletions
diff --git a/examples/widgetbinding/CMakeLists.txt b/examples/widgetbinding/CMakeLists.txt index e601a3579..1c5eefa50 100644 --- a/examples/widgetbinding/CMakeLists.txt +++ b/examples/widgetbinding/CMakeLists.txt @@ -1,5 +1,8 @@ -cmake_minimum_required(VERSION 3.16) -cmake_policy(VERSION 3.16) +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.18) +cmake_policy(VERSION 3.18) # Enable policy to not use RPATH settings for install_name on macOS. if(POLICY CMP0068) @@ -16,14 +19,12 @@ project(wiggly LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) +find_package(Qt6 COMPONENTS Core Gui Widgets) # ================================ General configuration ====================================== -# Set CPP standard to C++11 minimum. -set(CMAKE_CXX_STANDARD 11) +# Set CPP standard to C++17 minimum. +set(CMAKE_CXX_STANDARD 17) # The wiggly library for which we will create bindings. You can change the name to something # relevant for your project. @@ -52,7 +53,21 @@ set(generated_sources # ================================== Shiboken detection ====================================== # Use provided python interpreter if given. if(NOT python_interpreter) - find_program(python_interpreter "python") + if(WIN32 AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + find_program(python_interpreter "python_d") + if(NOT python_interpreter) + message(FATAL_ERROR + "A debug Python interpreter could not be found, which is a requirement when " + "building this example in a debug configuration. Make sure python_d.exe is in " + "PATH.") + endif() + else() + find_program(python_interpreter "python") + if(NOT python_interpreter) + message(FATAL_ERROR + "No Python interpreter could be found. Make sure python is in PATH.") + endif() + endif() endif() message(STATUS "Using python interpreter: ${python_interpreter}") @@ -204,7 +219,11 @@ set_property(TARGET ${bindings_library} PROPERTY PREFIX "") set_property(TARGET ${bindings_library} PROPERTY OUTPUT_NAME "${bindings_library}${PYTHON_EXTENSION_SUFFIX}") if(WIN32) - set_property(TARGET ${bindings_library} PROPERTY SUFFIX ".pyd") + if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + set_property(TARGET ${bindings_library} PROPERTY SUFFIX "_d.pyd") + else() + set_property(TARGET ${bindings_library} PROPERTY SUFFIX ".pyd") + endif() endif() # Make sure the linker doesn't complain about not finding Python symbols on macOS. diff --git a/examples/widgetbinding/dialog.py b/examples/widgetbinding/dialog.py index 20dbd476c..1bd127804 100644 --- a/examples/widgetbinding/dialog.py +++ b/examples/widgetbinding/dialog.py @@ -21,12 +21,13 @@ class Dialog(QDialog): layout.addWidget(wiggly_widget_py) layout.addWidget(wiggly_widget_cpp) layout.addWidget(lineEdit) + lineEdit.setClearButtonEnabled(True) wiggly_widget_py.running = True wiggly_widget_cpp.setRunning(True) lineEdit.textChanged.connect(wiggly_widget_py.setText) lineEdit.textChanged.connect(wiggly_widget_cpp.setText) - lineEdit.setText("Hello world!") + lineEdit.setText("🖖 Hello world!") self.setWindowTitle("Wiggly") self.resize(360, 145) diff --git a/examples/widgetbinding/README.md b/examples/widgetbinding/doc/widgetbinding.md index 5fee93c8c..6355ea311 100644 --- a/examples/widgetbinding/README.md +++ b/examples/widgetbinding/doc/widgetbinding.md @@ -1,7 +1,5 @@ -# WigglyWidget - -The original Qt/C++ example can be found here: -https://doc.qt.io/qt-6/qtwidgets-widgets-wiggly-example.html +(widgetbinding-example)= +# WigglyWidget Example This example shows how to interact with a custom widget from two different ways: @@ -55,7 +53,7 @@ cd C:\pyside-setup\examples\widgetbinding ```bash mkdir build cd build -cmake -H.. -B. -G Ninja -DCMAKE_BUILD_TYPE=Release +cmake -S.. -B. -G Ninja -DCMAKE_BUILD_TYPE=Release ninja ninja install cd .. diff --git a/examples/widgetbinding/doc/widgetbinding.pyproject b/examples/widgetbinding/doc/widgetbinding.pyproject new file mode 100644 index 000000000..e423ea347 --- /dev/null +++ b/examples/widgetbinding/doc/widgetbinding.pyproject @@ -0,0 +1,10 @@ +{ + "files": ["../bindings.h", + "../dialog.py", + "../macros.h", + "../main.py", + "../registerwigglywidget.py", + "../wigglywidget.cpp", + "../wigglywidget.h", + "../wigglywidget.py"] +} diff --git a/examples/widgetbinding/wigglywidget.cpp b/examples/widgetbinding/wigglywidget.cpp index 79fc79ee4..6fdc65f39 100644 --- a/examples/widgetbinding/wigglywidget.cpp +++ b/examples/widgetbinding/wigglywidget.cpp @@ -39,14 +39,16 @@ void WigglyWidget::paintEvent(QPaintEvent * /* event */) //! [3] QPainter painter(this); //! [3] //! [4] - for (int i = 0; i < m_text.size(); ++i) { - int index = (m_step + i) % 16; + int offset = 0; + const auto codePoints = m_text.toUcs4(); + for (char32_t codePoint : codePoints) { + const int index = (m_step + offset++) % 16; color.setHsv((15 - index) * 16, 255, 191); painter.setPen(color); - const QChar c = m_text.at(i); + QString symbol = QString::fromUcs4(&codePoint, 1); const int dy = (sineTable[index] * metrics.height()) / 400; - painter.drawText(x, y - dy, c); - x += metrics.horizontalAdvance(c); + painter.drawText(x, y - dy, symbol); + x += metrics.horizontalAdvance(symbol); } } //! [4] |