aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <Cristian.Maureira-Fredes@qt.io>2020-05-23 14:10:31 +0200
committerCristian Maureira-Fredes <Cristian.Maureira-Fredes@qt.io>2020-05-25 18:37:51 +0200
commitb8427aa18824e89a3b28b6b821da4efe0827951b (patch)
treea440c1cab4e85c8c9ed95e38969e21707fc97087
parent89f5b036809e8c92d1ce5845417b644064953507 (diff)
Rename and update some snippets
* Renaming a few .cpp files into .py * Replacing the use of SIGNAL() and SLOT() * Fixing Python syntax * Removing C++-isms from translated Python code * Including the snippets from QStackedLayout Task-number: PYSIDE-691 Fixes: PYSIDE-1309 Change-Id: I431be3d930b2adc36a22118901baa6799581adb2 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.py (renamed from sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.cpp)5
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.py (renamed from sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.cpp)158
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.py74
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp73
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.py71
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.py (renamed from sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.cpp)40
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.h81
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.py65
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedlayout/main.py87
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.py (renamed from sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.cpp)3
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.py (renamed from sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.cpp)12
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.py (renamed from sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp)6
-rw-r--r--sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/template.py66
-rw-r--r--sources/pyside2/doc/codesnippets/examples/dialogs/classwizard/classwizard.py (renamed from sources/pyside2/doc/codesnippets/examples/dialogs/classwizard/classwizard.cpp)15
-rw-r--r--sources/pyside2/doc/codesnippets/examples/dialogs/extension/finddialog.py (renamed from sources/pyside2/doc/codesnippets/examples/dialogs/extension/finddialog.cpp)2
-rw-r--r--sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.h (renamed from sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.cpp)71
-rw-r--r--sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.py (renamed from sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.cpp)82
-rw-r--r--sources/pyside2/doc/codesnippets/examples/mainwindows/dockwidgets/mainwindow.py (renamed from sources/pyside2/doc/codesnippets/examples/mainwindows/dockwidgets/mainwindow.cpp)10
-rw-r--r--sources/pyside2/doc/codesnippets/examples/mainwindows/mainwindow.py (renamed from sources/pyside2/doc/codesnippets/examples/mainwindows/mainwindow.cpp)43
-rw-r--r--sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.cpp381
-rw-r--r--sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.py360
-rw-r--r--sources/pyside2/doc/codesnippets/examples/mainwindows/menus/mainwindow.py (renamed from sources/pyside2/doc/codesnippets/examples/mainwindows/menus/mainwindow.cpp)43
-rw-r--r--sources/pyside2/doc/codesnippets/examples/widgets/spinboxes/window.py (renamed from sources/pyside2/doc/codesnippets/examples/widgets/spinboxes/window.cpp)10
23 files changed, 984 insertions, 774 deletions
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.py
index 726ceb818..1cbd56241 100644
--- a/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.cpp
+++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/clipboard/clipwindow.py
@@ -65,10 +65,9 @@ def __init__(self, parent):
previousItems = QListWidget(centralWidget)
//! [0]
- connect(clipboard, SIGNAL("dataChanged()"), self, SLOT("updateClipboard()"))
+ clipboard.dataChanged.connect(self.updateClipboard)
//! [0]
- connect(mimeTypeCombo, SIGNAL("activated(const QString &)"),
- self, SLOT("updateData(const QString &))")
+ mimeTypeCombo.activated[str].connect(self.updateData)
currentLayout = QVBoxLayout(currentItem)
currentLayout.addWidget(mimeTypeLabel)
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.py
index 1de4dbbe8..7e50f6701 100644
--- a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.cpp
+++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/src_corelib_kernel_qobject.py
@@ -1,52 +1,52 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the documentation of Qt for Python.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## BSD License Usage
+## Alternatively, you may use this file under the terms of the BSD license
+## as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+############################################################################
//! [0]
lineEdit = qt_find_obj_child(myWidget, "QLineEdit", "my line edit")
@@ -96,8 +96,8 @@ layout.inherits("QLayoutItem") # returns false
//! [5]
-print "MyClass::setPrecision(): (%s) invalid precision %f" % \
- (qPrintable(objectName()), newPrecision)
+print("MyClass.setPrecision(): ({}) invalid precision {}".format(qPrintable(objectName()),
+ newPrecision))
//! [5]
@@ -112,7 +112,7 @@ class MainWindow(QMainWindow):
if obj == textEdit:
if event.type() == QEvent.KeyPress:
keyEvent = event
- print "Ate key press", keyEvent.key()
+ print("Ate key press", keyEvent.key())
return true
else:
return false
@@ -138,14 +138,14 @@ class MyObject(QObject):
def timerEvent(self, event):
- print "Timer ID:", event.timerId()
+ print("Timer ID:", event.timerId())
//! [8]
//! [9]
-list = window().queryList("QAbstractButton")
-for obj in list:
+a_list = window().queryList("QAbstractButton")
+for obj in a_list:
obj.setEnabled(false)
//! [9]
@@ -156,7 +156,7 @@ button = parentWidget.findChild(QPushButton, "button1")
//! [11]
-list = parentWidget.findChild(QListWidget)
+a_list = parentWidget.findChild(QListWidget)
//! [11]
@@ -179,7 +179,7 @@ monitoredObj.installEventFilter(filterObj)
class KeyPressEater(QObject):
def eventFilter(self, obj, event):
if event.type() == QEvent.KeyPress:
- print "Ate key press", event.key()
+ print("Ate key press", event.key())
return True
else:
# standard event processing
@@ -234,15 +234,16 @@ if receivers(SIGNAL('valueChanged()')) > 0:
//! [22]
label = QLabel()
scrollBar = QScrollBar()
-QObject.connect(scrollBar, SIGNAL('valueChanged()'),
- label, SLOT('setNum()'))
+QObject.connect(scrollBar, SIGNAL('valueChanged(int)'),
+ label, SLOT('setNum(int)'));
+# or scrollBar.valueChanged.connect(label.setNum)
//! [22]
//! [23]
// WRONG
-QObject.connect(scrollBar, SIGNAL('valueChanged()'),
- label, SLOT('setNum()'));
+QObject.connect(scrollBar, SIGNAL('valueChanged(int value)'),
+ label, SLOT('setNum(int value)'));
//! [23]
@@ -250,8 +251,7 @@ QObject.connect(scrollBar, SIGNAL('valueChanged()'),
class MyWidget(QWidget):
def __init__(self):
myButton = QPushButton(self)
- connect(myButton, SIGNAL('clicked()'),
- self, SIGNAL('buttonClicked()'))
+ myButton.clicked.connect(self.buttonClicked)
//! [24]
@@ -323,7 +323,7 @@ Q_PROPERTY(type name
[DESIGNABLE bool]
[SCRIPTABLE bool]
[STORED bool]
- [USER bool])
+ [USER bool])
//! [36]
@@ -333,34 +333,40 @@ Q_PROPERTY(QString title READ title WRITE setTitle USER true)
//! [38]
-#this not apply for Python
+#this does not apply to Python
class MyClass(QObject):
- Q_OBJECT
- Q_ENUMS(Priority)
+ #Q_OBJECT, not needed
+ #Q_ENUMS(Priority), not supported
-public:
- MyClass(QObject *parent = 0);
- ~MyClass();
+ def __init__(self, parent=None):
+ pass
- enum Priority { High, Low, VeryHigh, VeryLow };
- void setPriority(Priority priority);
- Priority priority() const;
+ class Priority(Enum):
+ High = 1
+ Low = 2
+ VeryHigh = 3
+ VeryLow 4
+
+ def setPriority(self, priority):
+ pass
+
+ priority = Property(...)
};
//! [38]
//! [39]
-#this not apply for Python
+#this does not apply to Python
Q_FLAGS(Options Alignment)
//! [39]
//! [40]
-//: This name refers to a host name.
+# This name refers to a host name.
hostNameLabel.setText(self.tr("Name:"))
-#: This text refers to a C++ code example.
+# This text refers to a C++ code example.
example = self.tr("Example")
//! [40]
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.py b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.py
new file mode 100644
index 000000000..6cf5dd21c
--- /dev/null
+++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.py
@@ -0,0 +1,74 @@
+############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the documentation of Qt for Python.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## BSD License Usage
+## Alternatively, you may use this file under the terms of the BSD license
+## as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+############################################################################
+
+//! [0]
+ formWindow = QDesignerFormWindowInterface()
+ formWindow = QDesignerFormWindowInterface.findFormWindow(myWidget)
+//! [0]
+
+
+//! [1]
+ forms = [] # QList<QDesignerFormWindowInterface>
+ formWindow = QDesignerFormWindowInterface()
+
+ manager = formEditor.formWindowManager()
+
+ for i in range(manager.formWindowCount()):
+ formWindow = manager.formWindow(i)
+ forms.append(formWindow)
+//! [1]
+
+
+//! [2]
+ if formWindow.isManaged(myWidget):
+ formWindow.manageWidget(myWidget.childWidget)
+//! [2]
+
+
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp
deleted file mode 100644
index 255231512..000000000
--- a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [0]
- QDesignerPropertyEditorInterface *propertyEditor = 0;
- propertyEditor = formEditor->propertyEditor();
-
- connect(propertyEditor, SIGNAL(propertyChanged(QString, QVariant)),
- this, SLOT(checkProperty(QString, QVariant)));
-//! [0]
-
-
-//! [1]
- void checkProperty(QString property, QVariant value) {
- QDesignerPropertyEditorInterface *propertyEditor = 0;
- propertyEditor = formEditor->propertyEditor();
-
- QObject *object = propertyeditor->object();
- MyCustomWidget *widget = qobject_cast<MyCustomWidget>(object);
-
- if (widget && property == aProperty && value != expectedValue)
- {...}
- }
-//! [1]
-
-
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.py b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.py
new file mode 100644
index 000000000..1e2ac506f
--- /dev/null
+++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractpropertyeditor.py
@@ -0,0 +1,71 @@
+############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the documentation of Qt for Python.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## BSD License Usage
+## Alternatively, you may use this file under the terms of the BSD license
+## as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+############################################################################
+
+//! [0]
+ propertyEdit = QDesignerPropertyEditorInterface()
+ propertyEditor = formEditor.propertyEditor()
+
+ propertyEditor.propertyChanged.connect(self.checkProperty)
+//! [0]
+
+
+//! [1]
+ def checkProperty(self, property, value):
+ propertyEditor = QDesignerPropertyEditorInterface()
+ propertyEditor = formEditor.propertyEditor()
+
+ object = propertyeditor.object()
+ widget = MyCustomWidget(object)
+
+ if (widget and property == aProperty and value != expectedValue):
+ # ...
+//! [1]
+
+
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.py
index 047434f6d..7bdcb0c91 100644
--- a/sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.cpp
+++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dialogs/dialogs.py
@@ -50,12 +50,10 @@
//! [0]
-def find(self)
-
- if !self.findDialog:
+def find(self):
+ if not self.findDialog:
self.findDialog = FindDialog(self)
- connect(findDialog, SIGNAL("findNext()"), self, SLOT("findNext()"))
-
+ self.findDialog.findNext.connect(self.findNext)
self.findDialog.show()
self.findDialog.raise()
@@ -72,58 +70,54 @@ def countWords(self):
//! [1]
//! [2]
- mb = QMessageBox("Application Name",
- "Hardware failure.\n\nDisk error detected\nDo you want to stop?",
- QMessageBox.Question,
- QMessageBox.Yes | QMessageBox.Default,
- QMessageBox.No | QMessageBox.Escape,
- QMessageBox.NoButton)
- if mb.exec() == QMessageBox.No:
- # try again
+ mb = QMessageBox("Application Name",
+ "Hardware failure.\n\nDisk error detected\nDo you want to stop?",
+ QMessageBox.Question,
+ QMessageBox.Yes | QMessageBox.Default,
+ QMessageBox.No | QMessageBox.Escape,
+ QMessageBox.NoButton)
+ if mb.exec() == QMessageBox.No:
+ # try again
//! [2]
//! [3]
progress = QProgressDialog("Copying files...", "Abort Copy", 0, numFiles, self)
progress.setWindowModality(Qt.WindowModal)
- for i in rang(numFiles):
+ for i in range(numFiles):
progress.setValue(i)
if progress.wasCanceled():
break
#... copy one file
-
+
progress.setValue(numFiles)
//! [3]
//! [4]
# Operation constructor
-def __init__(self, parent):
+def __init__(self, parent=None):
QObject.__init__(self, parent)
pd = QProgressDialog("Operation in progress.", "Cancel", 0, 100)
- connect(pd, SIGNAL("canceled()"), self, SLOT("cancel()"))
+ pd.canceled.connect(self.cancel)
t = QTimer(self)
- connect(t, SIGNAL("timeout()"), self, SLOT("perform()"))
+ t.timeout.connect(self.perform)
t.start(0)
//! [4] //! [5]
def perform(self):
-
pd.setValue(steps)
#... perform one percent of the operation
- steps++
+ steps += 1
if steps > pd.maximum():
t.stop()
//! [5] //! [6]
def cancel(self):
-
t.stop()
#... cleanup
//! [6]
-
-
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.h b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.h
deleted file mode 100644
index 8607b6953..000000000
--- a/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef WINDOW_H
-#define WINDOW_H
-
-#include <QString>
-#include <QStringList>
-#include <QWidget>
-
-class QComboBox;
-class QFrame;
-class QTextBrowser;
-
-class Window : public QWidget
-{
- Q_OBJECT
-
-public:
- Window(QWidget *parent = 0);
-
-protected:
- void dragEnterEvent(QDragEnterEvent *event);
- void dropEvent(QDropEvent *event);
-
-private:
- QComboBox *mimeTypeCombo;
- QFrame *dropFrame;
- QTextBrowser *textBrowser;
- QString oldText;
- QStringList oldMimeTypes;
-};
-
-#endif
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.py b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.py
new file mode 100644
index 000000000..66a6a7ba2
--- /dev/null
+++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/dropevents/window.py
@@ -0,0 +1,65 @@
+############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the examples of Qt for Python.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## BSD License Usage
+## Alternatively, you may use this file under the terms of the BSD license
+## as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+############################################################################
+
+from PySide2.QtWidgets import QWidget, QComboBox, QFrame, QTextBrowser
+
+class Window(QWidget):
+
+ def __init__(self, parent=None):
+ self.mimeTypeCombo = QComboBox()
+ self.dropFrame = QFrame()
+ self.textBrowser = QTextBrowser()
+ self.oldText = ""
+ self.oldMimeTypes = []
+
+ def dragEnterEvent(self, event):
+ pass
+ def dropEvent(self, event):
+ pass
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedlayout/main.py b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedlayout/main.py
new file mode 100644
index 000000000..184128406
--- /dev/null
+++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedlayout/main.py
@@ -0,0 +1,87 @@
+############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the documentation of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## BSD License Usage
+## Alternatively, you may use this file under the terms of the BSD license
+## as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+############################################################################
+
+from PySide2.QtWidgets import QApplication, QWidget, QStackedLayout, QComboBox
+
+class Widget(QWidget)
+ def __init__(self, parent=None):
+ QWidget.__init__(self, parent)
+//! [0]
+ self.firstPageWidget = QWidget()
+ self.secondPageWidget = QWidget()
+ self.thirdPageWidget = QWidget()
+
+ self.stackedLayout = QStackedLayout()
+ self.stackedLayout.addWidget(self.firstPageWidget)
+ self.stackedLayout.addWidget(self.secondPageWidget)
+ self.stackedLayout.addWidget(self.thirdPageWidget)
+
+//! [0] //! [1]
+ self.pageComboBox = QComboBox()
+ self.pageComboBox.addItem(tr("Page 1"))
+ self.pageComboBox.addItem(tr("Page 2"))
+ self.pageComboBox.addItem(tr("Page 3"))
+ self.pageComboBox.activated.connect(self.stackedLayout.setCurrentIndex)
+//! [1]
+
+//! [2]
+ self.mainLayout = QVBoxLayout()
+//! [2]
+ self.mainLayout.addWidget(self.pageComboBox)
+//! [3]
+ self.mainLayout.addLayout(self.stackedLayout)
+ self.setLayout(self.mainLayout)
+//! [3]
+
+if __name__ == "__main__":
+ app = QApplication(sys.argv)
+ widget = Widget()
+ widget.show()
+ sys.exit(app.exec_())
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.py
index 98a08be98..6f2c49d8e 100644
--- a/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.cpp
+++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qstackedwidget/main.py
@@ -64,8 +64,7 @@
pageComboBox.addItem(tr("Page 1"))
pageComboBox.addItem(tr("Page 2"))
pageComboBox.addItem(tr("Page 3"))
- connect(pageComboBox, SIGNAL("activated(int)"),
- stackedWidget, SLOT("setCurrentIndex(int)"))
+ pageComboBox.activated[int].connect(stackedWidget.setCurrentIndex)
//! [1] //! [2]
layout = QVBoxLayout()
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.py
index 734f603a9..16c12b7bc 100644
--- a/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.cpp
+++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/qxmlquery/bindingExample.py
@@ -49,11 +49,11 @@
****************************************************************************/
//! [0]
- QBuffer device;
- device.setData(myQString.toUtf8());
- device.open(QIODevice::ReadOnly);
+ device = QBuffer()
+ device.setData(myQString.toUtf8())
+ device.open(QIODevice.ReadOnly)
- QXmlQuery query;
- query.setQuery("doc($inputDocument)/query[theDocument]");
- query.bindVariable("inputDocument", &device);
+ query = QXmlQuery()
+ query.setQuery("doc($inputDocument)/query[theDocument]")
+ query.bindVariable("inputDocument", device)
//! [0]
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp b/sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.py
index 29ac9c87d..7c28cf5e6 100644
--- a/sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.cpp
+++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/sqldatabase/sqldatabase.py
@@ -77,7 +77,7 @@ def QSqlField_snippets():
//! [3]
field = QSqlField("age", QVariant.Int)
- field.setValue(QString("123")) # casts QString to int
+ field.setValue(str(123)) # casts str to int
//! [3]
//! [4]
@@ -247,7 +247,7 @@ def QSqlTableModel_snippets():
//! [25]
model = QSqlTableModel()
model.setTable("employee")
- QString name = model.record(4).value("name")
+ name = model.record(4).value("name")
//! [25]
def sql_intro_snippets():
@@ -351,7 +351,7 @@ def sql_intro_snippets():
employeeId = query.value(0)
query.exec_("INSERT INTO project (id, name, ownerid) "
"VALUES (201, 'Manhattan Project', "
- + QString.number(employeeId) + ')')
+ + str(employeeId) + ')')
QSqlDatabase.database().commit()
//! [39]
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/template.py b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/template.py
new file mode 100644
index 000000000..d38829fc7
--- /dev/null
+++ b/sources/pyside2/doc/codesnippets/doc/src/snippets/widgets-tutorial/template.py
@@ -0,0 +1,66 @@
+############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the documentation of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## BSD License Usage
+## Alternatively, you may use this file under the terms of the BSD license
+## as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+############################################################################
+
+//! [main.cpp body]
+import sys
+from PySide2.QtWidgets import QApplication
+
+# Include header files for application components.
+# ...
+
+if __name__ == "__main__":
+ app = QApplication(sys.argv)
+
+ # Set up and show widgets.
+ # ...
+
+ sys.exit(app.exec_())
+}
+//! [main.cpp body]
diff --git a/sources/pyside2/doc/codesnippets/examples/dialogs/classwizard/classwizard.cpp b/sources/pyside2/doc/codesnippets/examples/dialogs/classwizard/classwizard.py
index 897410ed7..08032cf2a 100644
--- a/sources/pyside2/doc/codesnippets/examples/dialogs/classwizard/classwizard.cpp
+++ b/sources/pyside2/doc/codesnippets/examples/dialogs/classwizard/classwizard.py
@@ -142,8 +142,7 @@ class ClassInfoPage(QWizardPage):
defaultCtorRadioButton.setChecked(True)
- self.connect(defaultCtorRadioButton, SIGNAL("toggled(bool)"),
- copyCtorCheckBox, SLOT("setEnabled(bool)"))
+ defaultCtorRadioButton.toggled[bool].connect(copyCtorCheckBox.setEnabled)
//! [11] //! [12]
registerField("className*", classNameLineEdit)
@@ -201,14 +200,10 @@ class CodeStylePage(QWizardPage):
baseIncludeLineEdit = QLineEdit()
baseIncludeLabel.setBuddy(baseIncludeLineEdit)
- self.connect(protectCheckBox, SIGNAL("toggled(bool)"),
- macroNameLabel, SLOT("setEnabled(bool)"))
- self.connect(protectCheckBox, SIGNAL("toggled(bool)"),
- macroNameLineEdit, SLOT("setEnabled(bool)"))
- self.connect(includeBaseCheckBox, SIGNAL("toggled(bool)"),
- baseIncludeLabel, SLOT("setEnabled(bool)"))
- self.connect(includeBaseCheckBox, SIGNAL(toggled(bool)),
- baseIncludeLineEdit, SLOT("setEnabled(bool)"))
+ protectCheckBox.toggled[bool].connect(macroNameLabel.setEnabled)
+ protectCheckBox.toggled[bool].connect(macroNameLineEdit.setEnabled)
+ includeBaseCheckBox.toggled[bool].connect(baseIncludeLabel.setEnabled)
+ includeBaseCheckBox.toggled[bool].connect(baseIncludeLineEdit.setEnabled)
self.registerField("comment", commentCheckBox)
self.registerField("protect", protectCheckBox)
diff --git a/sources/pyside2/doc/codesnippets/examples/dialogs/extension/finddialog.cpp b/sources/pyside2/doc/codesnippets/examples/dialogs/extension/finddialog.py
index a8496f4c8..1872e631b 100644
--- a/sources/pyside2/doc/codesnippets/examples/dialogs/extension/finddialog.cpp
+++ b/sources/pyside2/doc/codesnippets/examples/dialogs/extension/finddialog.py
@@ -85,7 +85,7 @@ def __init__(self, parent):
//! [2]
//! [3]
- connect(moreButton, SIGNAL("toggled(bool)"), extension, SLOT("setVisible(bool)"))
+ moreButton.toggled[bool].connect(extension.setVisible)
extensionLayout = QVBoxLayout()
extensionLayout.setMargin(0)
diff --git a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.h
index f9d97e6ce..bdb7bcf22 100644
--- a/sources/pyside2/doc/codesnippets/doc/src/snippets/code/tools_designer_src_lib_sdk_abstractformwindow.cpp
+++ b/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.h
@@ -3,7 +3,7 @@
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
-** This file is part of the documentation of Qt for Python.
+** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
@@ -48,28 +48,65 @@
**
****************************************************************************/
+from PySide2.QtWidgets import (QAction, QApplication, QMainWindow, QMenu,
+ QPlainTextEdit, QSessionManager)
+
+
//! [0]
- QDesignerFormWindowInterface *formWindow;
- formWindow = QDesignerFormWindowInterface::findFormWindow(myWidget);
-//! [0]
+class MainWindow(QMainWindow):
+ def __init__(self, parent=None):
+ self.textEdit = QPlainTextEdit()
+ self.curFile = ""
+ # ...
+
+ def loadFile(self, fileName):
+ pass
+
+ def closeEvent(self, event):
+ pass
+
+ def newFile(self):
+ pass
+ def open(self):
+ pass
-//! [1]
- QList<QDesignerFormWindowInterface *> forms;
- QDesignerFormWindowInterface *formWindow;
+ def save(self):
+ pass
- QDesignerFormWindowManagerInterface *manager = formEditor->formWindowManager();
+ def saveAs(self):
+ pass
- for (int i = 0; i < manager->formWindowCount(); i++) {
- formWindow = manager->formWindow(i);
- forms.append(formWindow);
- }
-//! [1]
+ def about(self):
+ pass
+ def documentWasModified(self):
+ pass
+ # Enable this only if QT_NO_SESSIONMANAGER is not defined
+ # def commitData(self):
+ # pass
-//! [2]
- if (formWindow->isManaged(myWidget))
- formWindow->manageWidget(myWidget->childWidget);
-//! [2]
+ def createActions(self):
+ pass
+ def createStatusBar(self):
+ pass
+ def readSettings(self):
+ pass
+
+ def writeSettings(self):
+ pass
+
+ def maybeSave(self):
+ pass
+
+ def saveFile(self, fileName):
+ pass
+
+ def setCurrentFile(self, fileName):
+ pass
+
+ def strippedName(self, fullFileName):
+ pass
+//! [0]
diff --git a/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.py
index b0331aa79..f976bb8e3 100644
--- a/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.cpp
+++ b/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.py
@@ -49,28 +49,30 @@
############################################################################
//! [0]
-from PySide2.QtGui import *
+from PySide2.QtCore import Qt, QFile, QFileInfo, QSettings, QTextStream
+from PySide2.QtGui import QIcon
+from PySide2.Widgets import (QAction, QApplication, QFileDialog, QMainWindow,
+ QPlainTextEdit, QFileDialog, QMessageBox, )
//! [0]
//! [1]
-def __init__(self):
+def __init__(self, parent=None):
QMainWindow.__init__(self)
//! [1] //! [2]
- textEdit = QPlainTextEdit()
- setCentralWidget(textEdit)
+ self.textEdit = QPlainTextEdit()
+ self.setCentralWidget(textEdit)
- createActions()
- createMenus()
- createToolBars()
- createStatusBar()
+ self.createActions()
+ self.createMenus()
+ self.createToolBars()
+ self.createStatusBar()
- readSettings()
+ self.readSettings()
- connect(textEdit.document(), SIGNAL("contentsChanged()"),
- self, SLOT("documentWasModified()"))
+ self.textEdit.document().contentsChanged.connect(self.documentWasModified)
- setCurrentFile("")
- setUnifiedTitleAndToolBarOnMac(True)
+ self.setCurrentFile("")
+ self.setUnifiedTitleAndToolBarOnMac(True)
//! [2]
@@ -97,7 +99,7 @@ def open(self):
//! [7] //! [8]
if maybeSave():
fileName = QFileDialog.getOpenFileName(self)
- if !fileName.isEmpty():
+ if not fileName.isEmpty():
loadFile(fileName)
//! [8]
@@ -142,70 +144,68 @@ def MainWindow.createActions(self):
Act = QAction(QIcon(":/images/new.png"), tr("&New"), self)
Act.setShortcuts(QKeySequence.New)
Act.setStatusTip(tr("Create a new file"))
- connect(Act, SIGNAL("triggered()"), self, SLOT("newFile()"))
+ Act.triggered.connect(newFile)
//! [19]
- openAct = QAction(QIcon(":/images/open.png"), tr("&Open..."), self)
+ openAct = QAction(QIcon(":/images/open.png"), tr("&Open..."), self)
openAct.setShortcuts(QKeySequence.Open)
openAct.setStatusTip(tr("Open an existing file"))
- connect(openAct, SIGNAL("triggered()"), self, SLOT("open()"))
+ openAct.triggered.connect(open)
//! [18] //! [19]
- saveAct = QAction(QIcon(":/images/save.png"), tr("&Save"), self)
+ saveAct = QAction(QIcon(":/images/save.png"), tr("&Save"), self)
saveAct.setShortcuts(QKeySequence.Save)
saveAct.setStatusTip(tr("Save the document to disk"))
- connect(saveAct, SIGNAL("triggered()"), self, SLOT("save()"))
+ saveAct.triggered.connect(save)
- saveAsAct = QAction(tr("Save &As..."), self)
+ saveAsAct = QAction(tr("Save &As..."), self)
saveAsAct.setShortcuts(QKeySequence.SaveAs)
saveAsAct.setStatusTip(tr("Save the document under a name"))
- connect(saveAsAct, SIGNAL("triggered()"), self, SLOT("saveAs()"))
+ saveAsAct.triggered.connect(saveAs)
//! [20]
- exitAct = QAction(tr("E&xit"), self)
+ exitAct = QAction(tr("E&xit"), self)
exitAct.setShortcut(tr("Ctrl+Q"))
//! [20]
exitAct.setStatusTip(tr("Exit the application"))
- connect(exitAct, SIGNAL("triggered()"), self, SLOT("close()"))
+ exitAct.triggered.connect(close)
//! [21]
- cutAct = QAction(QIcon(":/images/cut.png"), tr("Cu&t"), self)
+ cutAct = QAction(QIcon(":/images/cut.png"), tr("Cu&t"), self)
//! [21]
cutAct.setShortcuts(QKeySequence.Cut)
cutAct.setStatusTip(tr("Cut the current selection's contents to the "
"clipboard"))
- connect(cutAct, SIGNAL("triggered()"), textEdit, SLOT("cut()"))
+ cutAct.triggered.connect(cut)
- copyAct = QAction(QIcon(":/images/copy.png"), tr("&Copy"), self)
+ copyAct = QAction(QIcon(":/images/copy.png"), tr("&Copy"), self)
copyAct.setShortcuts(QKeySequence.Copy)
copyAct.setStatusTip(tr("Copy the current selection's contents to the "
"clipboard"))
- connect(copyAct, SIGNAL("triggered()"), textEdit, SLOT("copy()"))
+ copyAct.triggered.connect(copy)
- pasteAct = QAction(QIcon(":/images/paste.png"), tr("&Paste"), self)
+ pasteAct = QAction(QIcon(":/images/paste.png"), tr("&Paste"), self)
pasteAct.setShortcuts(QKeySequence.Paste)
pasteAct.setStatusTip(tr("Paste the clipboard's contents into the current "
"selection"))
- connect(pasteAct, SIGNAL("triggered()"), textEdit, SLOT("paste()"))
+ pasteAct.triggered.connect(textEdit.paste)
- aboutAct = QAction(tr("&About"), self)
+ aboutAct = QAction(tr("&About"), self)
aboutAct.setStatusTip(tr("Show the application's About box"))
- connect(aboutAct, SIGNAL("triggered()"), self, SLOT("about()"))
+ aboutAct.triggered.connect(about)
//! [22]
aboutQtAct = QAction(tr("About &Qt"), self)
aboutQtAct.setStatusTip(tr("Show the Qt library's About box"))
- connect(aboutQtAct, SIGNAL("triggered()"), qApp, SLOT("aboutQt()"))
+ aboutQtAct.triggered.connect(qApp.aboutQt)
//! [22]
//! [23]
cutAct.setEnabled(False)
//! [23] //! [24]
copyAct.setEnabled(False)
- connect(textEdit, SIGNAL("copyAvailable(bool)"),
- cutAct, SLOT("setEnabled(bool)"))
- connect(textEdit, SIGNAL("copyAvailable(bool)"),
- copyAct, SLOT("setEnabled(bool)"))
+ textEdit.copyAvailable[bool].connect(cutAct.setEnabled)
+ textEdit.copyAvailable[bool].connect(copyAct.setEnabled)
}
//! [24]
@@ -298,10 +298,8 @@ def loadFile(self, fileName):
//! [42] //! [43]
file = QFile(fileName)
if !file.open(QFile.ReadOnly | QFile.Text):
- QMessageBox.warning(self, tr("Application"),
- tr("Cannot read file %1:\n%2.")
- .arg(fileName)
- .arg(file.errorString()))
+ QMessageBox.warning(self, tr("Application"), tr("Cannot read file "
+ "{}:\n{}.".format(fileName, file.errorString())))
return
in = QTextStream(file)
@@ -309,8 +307,8 @@ def loadFile(self, fileName):
textEdit.setPlainText(in.readAll())
QApplication.restoreOverrideCursor()
- setCurrentFile(fileName)
- statusBar().showMessage(tr("File loaded"), 2000)
+ self.setCurrentFile(fileName)
+ self.statusBar().showMessage(tr("File loaded"), 2000)
//! [43]
diff --git a/sources/pyside2/doc/codesnippets/examples/mainwindows/dockwidgets/mainwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/dockwidgets/mainwindow.py
index e1a9f556e..55d551c24 100644
--- a/sources/pyside2/doc/codesnippets/examples/mainwindows/dockwidgets/mainwindow.cpp
+++ b/sources/pyside2/doc/codesnippets/examples/mainwindows/dockwidgets/mainwindow.py
@@ -142,7 +142,7 @@ def save(self):
.arg(fileName)
.arg(file.errorString()))
return
-
+
out = QTextStream(file)
QApplication.setOverrideCursor(Qt::WaitCursor)
@@ -177,7 +177,7 @@ def insertCustomer(self, customer):
for i in range(customerList.size()):
cursor.insertBlock()
cursor.insertText(customerList.at(i))
-
+
cursor.endEditBlock()
else:
oldcursor.endEditBlock()
@@ -248,8 +248,6 @@ def createDockWindows(self):
addDockWidget(Qt.RightDockWidgetArea, dock)
viewMenu.addAction(dock.toggleViewAction())
- connect(customerList, SIGNAL("currentTextChanged(const QString &)"),
- self, SLOT("insertCustomer(const QString &)"))
- connect(paragraphsList, SIGNAL("currentTextChanged(const QString &)"),
- self, SLOT("addParagraph(const QString &)"))
+ customerList.currentTextChanged[str].connect(self.insertCostumer)
+ paragraphsList.currentTextChanged[str].connect(self.addParagraph)
//! [9]
diff --git a/sources/pyside2/doc/codesnippets/examples/mainwindows/mainwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/mainwindow.py
index 6ed5f5466..b0bbed810 100644
--- a/sources/pyside2/doc/codesnippets/examples/mainwindows/mainwindow.cpp
+++ b/sources/pyside2/doc/codesnippets/examples/mainwindows/mainwindow.py
@@ -196,63 +196,63 @@ def createActions(self):
Act = new QAction(tr("&New"), self)
Act.setShortcuts(QKeySequence.New)
Act.setStatusTip(tr("Create a new file"))
- connect(Act, SIGNAL("triggered()"), self, SLOT("newFile()"))
+ Act.triggered.connect(newFile)
//! [4]
openAct = QAction(tr("&Open..."), self)
openAct.setShortcuts(QKeySequence.Open)
openAct.setStatusTip(tr("Open an existing file"))
- connect(openAct, SIGNAL("triggered()"), self, SLOT("open()"))
+ openAct.triggered.connect(open)
//! [5]
saveAct = QAction(tr("&Save"), self)
saveAct.setShortcuts(QKeySequence.Save)
saveAct.setStatusTip(tr("Save the document to disk"))
- connect(saveAct, SIGNAL("triggered()"), self, SLOT("save()"))
+ saveAct.triggered.connect(save)
printAct = QAction(tr("&Print..."), self)
printAct.setShortcuts(QKeySequence.Print)
printAct.setStatusTip(tr("Print the document"))
- connect(printAct, SIGNAL("triggered()"), self, SLOT("print_()"))
+ printAct.triggered.connect(print_)
exitAct = QAction(tr("E&xit"), self)
exitAct.setShortcut(tr("Ctrl+Q"))
exitAct.setStatusTip(tr("Exit the application"))
- connect(exitAct, SIGNAL("triggered()"), self, SLOT("close()"))
+ exitAct.triggered.connect(close)
undoAct = QAction(tr("&Undo"), self)
undoAct.setShortcuts(QKeySequence.Undo)
undoAct.setStatusTip(tr("Undo the last operation"))
- connect(undoAct, SIGNAL("triggered()"), self, SLOT("undo()"))
+ undoAct.triggered.connect(undo)
redoAct = QAction(tr("&Redo"), self)
redoAct.setShortcuts(QKeySequence.Redo)
redoAct.setStatusTip(tr("Redo the last operation"))
- connect(redoAct, SIGNAL("triggered()"), self, SLOT("redo()"))
+ redoAct.triggered.connect(redo)
cutAct = QAction(tr("Cu&t"), self)
cutAct.setShortcuts(QKeySequence.Cut)
cutAct.setStatusTip(tr("Cut the current selection's contents to the "
"clipboard"))
- connect(cutAct, SIGNAL("triggered()"), self, SLOT("cut()"))
+ cutAct.triggered.connect(cut)
copyAct = QAction(tr("&Copy"), self)
copyAct.setShortcut(tr("Ctrl+C"))
copyAct.setStatusTip(tr("Copy the current selection's contents to the "
"clipboard"))
- connect(copyAct, SIGNAL("triggered()"), self, SLOT("copy()"))
+ copyAct.triggered.connect(copy)
pasteAct = QAction(tr("&Paste"), self)
pasteAct.setShortcuts(QKeySequence.Paste)
pasteAct.setStatusTip(tr("Paste the clipboard's contents into the current "
"selection"))
- connect(pasteAct, SIGNAL("triggered()"), self, SLOT("paste()"))
+ pasteAct.triggered.connect(paste)
boldAct = QAction(tr("&Bold"), self)
boldAct.setCheckable(True)
boldAct.setShortcut(tr("Ctrl+B"))
boldAct.setStatusTip(tr("Make the text bold"))
- connect(boldAct, SIGNAL("triggered()"), self, SLOT("bold()"))
+ boldAct.triggered.connect(bold)
QFont boldFont = boldAct.font()
boldFont.setBold(True)
@@ -262,7 +262,7 @@ def createActions(self):
italicAct.setCheckable(True)
italicAct.setShortcut(tr("Ctrl+I"))
italicAct.setStatusTip(tr("Make the text italic"))
- connect(italicAct, SIGNAL("triggered()"), self, SLOT("italic()"))
+ italicAct.triggered.connect(italic)
QFont italicFont = italicAct.font()
italicFont.setItalic(True)
@@ -271,45 +271,44 @@ def createActions(self):
setLineSpacingAct = QAction(tr("Set &Line Spacing..."), self)
setLineSpacingAct.setStatusTip(tr("Change the gap between the lines of a "
"paragraph"))
- connect(setLineSpacingAct, SIGNAL("triggered()"), self, SLOT("setLineSpacing()"))
+ setLineSpacingAct.triggered.connect(setLineSpacing)
setParagraphSpacingAct = QAction(tr("Set &Paragraph Spacing..."), self)
setLineSpacingAct.setStatusTip(tr("Change the gap between paragraphs"))
- connect(setParagraphSpacingAct, SIGNAL("triggered()"),
- self, SLOT("setParagraphSpacing()"))
+ setParagraphSpacingAct.triggered.connect(setParagraphSpacing)
aboutAct = QAction(tr("&About"), self)
aboutAct.setStatusTip(tr("Show the application's About box"))
- connect(aboutAct, SIGNAL("triggered()"), self, SLOT("about()"))
+ aboutAct.triggered.connect(about)
aboutQtAct = QAction(tr("About &Qt"), self)
aboutQtAct.setStatusTip(tr("Show the Qt library's About box"))
- connect(aboutQtAct, SIGNAL("triggered()"), qApp, SLOT("aboutQt()"))
- connect(aboutQtAct, SIGNAL("triggered()"), self, SLOT("aboutQt()"))
+ aboutQtAct.triggered.connect(qApp.aboutQt)
+ aboutQtAct.triggered.connect(aboutQt)
leftAlignAct = QAction(tr("&Left Align"), self)
leftAlignAct.setCheckable(True)
leftAlignAct.setShortcut(tr("Ctrl+L"))
leftAlignAct.setStatusTip(tr("Left align the selected text"))
- connect(leftAlignAct, SIGNAL("triggered()"), self, SLOT("leftAlign()"))
+ leftAlignAct.triggered.connect(leftAlign)
rightAlignAct = QAction(tr("&Right Align"), self)
rightAlignAct.setCheckable(True)
rightAlignAct.setShortcut(tr("Ctrl+R"))
rightAlignAct.setStatusTip(tr("Right align the selected text"))
- connect(rightAlignAct, SIGNAL("triggered()"), self, SLOT("rightAlign()"))
+ rightAlignAct.triggered.connect.(rightAlign)
justifyAct = QAction(tr("&Justify"), self)
justifyAct.setCheckable(True)
justifyAct.setShortcut(tr("Ctrl+J"))
justifyAct.setStatusTip(tr("Justify the selected text"))
- connect(justifyAct, SIGNAL("triggered()"), self, SLOT("justify()"))
+ justifyAct.triggered.connect(justify)
centerAct = QAction(tr("&Center"), self)
centerAct.setCheckable(True)
centerAct.setShortcut(tr("Ctrl+E"))
centerAct.setStatusTip(tr("Center the selected text"))
- connect(centerAct, SIGNAL("triggered()"), self, SLOT("center()"))
+ centerAct.triggered.connect(center)
//! [6] //! [7]
alignmentGroup = QActionGroup(self)
diff --git a/sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.cpp
deleted file mode 100644
index cfee5cdca..000000000
--- a/sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.cpp
+++ /dev/null
@@ -1,381 +0,0 @@
-############################################################################
-##
-## Copyright (C) 2016 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of the examples of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:BSD$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## BSD License Usage
-## Alternatively, you may use this file under the terms of the BSD license
-## as follows:
-##
-## "Redistribution and use in source and binary forms, with or without
-## modification, are permitted provided that the following conditions are
-## met:
-## * Redistributions of source code must retain the above copyright
-## notice, this list of conditions and the following disclaimer.
-## * Redistributions in binary form must reproduce the above copyright
-## notice, this list of conditions and the following disclaimer in
-## the documentation and/or other materials provided with the
-## distribution.
-## * Neither the name of The Qt Company Ltd nor the names of its
-## contributors may be used to endorse or promote products derived
-## from this software without specific prior written permission.
-##
-##
-## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-##
-## $QT_END_LICENSE$
-##
-############################################################################
-
-from PySide2.QtGui import *
-
-def __init__(self):
-
- mdiArea = QMdiArea()
- mdiArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
- mdiArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
- setCentralWidget(mdiArea)
- connect(mdiArea, SIGNAL("subWindowActivated(QMdiSubWindow *)"),
- self, SLOT("updateMenus()"))
- windowMapper = QSignalMapper(self)
- connect(windowMapper, SIGNAL("mapped(QWidget *)"),
- self, SLOT("setActiveSubWindow(QWidget *)"))
-
- createActions()
- createMenus()
- createToolBars()
- createStatusBar()
- updateMenus()
-
- readSettings()
-
- setWindowTitle(tr("MDI"))
- setUnifiedTitleAndToolBarOnMac(True)
-
-
-def closeEvent(self, event):
- mdiArea.closeAllSubWindows()
- if self.activeMdiChild():
- event.ignore()
- else:
- self.writeSettings()
- event.accept()
-
-def File(self):
- child = self.createMdiChild()
- child.File()
- child.show()
-
-
-def open(self):
- fileName = QFileDialog.getOpenFileName(self)
- if !fileName.isEmpty()):
- existing = self.findMdiChild(fileName)
- if existing:
- mdiArea.setActiveSubWindow(existing)
- return
-
- child = createMdiChild()
- if child.loadFile(fileName)):
- statusBar().showMessage(tr("File loaded"), 2000)
- child.show()
- else:
- child.close()
-
-def save(self):
- if self.activeMdiChild() && self.activeMdiChild().save():
- self.statusBar().showMessage(tr("File saved"), 2000)
-
-def saveAs(self):
- if self.activeMdiChild() && self.activeMdiChild().saveAs():
- self.statusBar().showMessage(tr("File saved"), 2000)
-
-def cut(self):
- if self.activeMdiChild():
- self.activeMdiChild().cut()
-
-def copy(self):
- if self.activeMdiChild():
- activeMdiChild().copy()
-
-def paste(self):
- if self.activeMdiChild():
- activeMdiChild().paste()
-
-def about(self):
- QMessageBox.about(self, tr("About MDI"),
- tr("The <b>MDI</b> example demonstrates how to write multiple "
- "document interface applications using Qt.")")
-
-def updateMenus(self):
- hasMdiChild = (activeMdiChild() != 0)
- self.saveAct.setEnabled(hasMdiChild)
- self.saveAsAct.setEnabled(hasMdiChild)
- self.pasteAct.setEnabled(hasMdiChild)
- self.closeAct.setEnabled(hasMdiChild)
- self.closeAllAct.setEnabled(hasMdiChild)
- self.tileAct.setEnabled(hasMdiChild)
- self.cascadeAct.setEnabled(hasMdiChild)
- self.nextAct.setEnabled(hasMdiChild)
- self.previousAct.setEnabled(hasMdiChild)
- self.separatorAct.setVisible(hasMdiChild)
-
- hasSelection = (self.activeMdiChild() &&
- self.activeMdiChild().textCursor().hasSelection()")
- self.cutAct.setEnabled(hasSelection)
- self.copyAct.setEnabled(hasSelection)
-
-def updateWindowMenu(self):
- self.windowMenu.clear()
- self.windowMenu.addAction(closeAct)
- self.windowMenu.addAction(closeAllAct)
- self.windowMenu.addSeparator()
- self.windowMenu.addAction(tileAct)
- self.windowMenu.addAction(cascadeAct)
- self.windowMenu.addSeparator()
- self.windowMenu.addAction(nextAct)
- self.windowMenu.addAction(previousAct)
- self.windowMenu.addAction(separatorAct)
-
- windows = mdiArea.subWindowList()
- separatorAct.setVisible(!windows.isEmpty()")
-
- for i in range((int i = 0 i < windows.size(); ++i)
- MdiChild *child = qobject_cast<MdiChild *>(windows.at(i).widget()")
-
- QString text
- if (i < 9)
- text = tr("&%1 %2").arg(i + 1)
- .arg(child.userFriendlyCurrentFile()")
- else
- text = tr("%1 %2").arg(i + 1)
- .arg(child.userFriendlyCurrentFile()")
-
- QAction *action = windowMenu.addAction(text)
- action.setCheckable(True)
- action .setChecked(child == activeMdiChild()")
- connect(action, SIGNAL("triggered()"), windowMapper, SLOT("map()"))
- windowMapper.setMapping(action, windows.at(i)")
-
-
-
-MdiChild *createMdiChild()
-
- MdiChild *child = MdiChild
- mdiArea.addSubWindow(child)
-
- connect(child, SIGNAL("copyAvailable(bool)"),
- cutAct, SLOT("setEnabled(bool)"))
- connect(child, SIGNAL("copyAvailable(bool)"),
- copyAct, SLOT("setEnabled(bool)"))
-
- return child
-
-
-def createActions()
-
- Act = new QAction(QIcon(":/images/new.png"), tr("&New"), self)
- Act.setShortcuts(QKeySequence.New)
- Act.setStatusTip(tr("Create a new file")")
- connect(Act, SIGNAL("triggered()"), self, SLOT("newFile()"))
-
- openAct = QAction(QIcon(":/images/open.png"), tr("&Open..."), self)
- openAct.setShortcuts(QKeySequence.Open)
- openAct.setStatusTip(tr("Open an existing file")")
- connect(openAct, SIGNAL("triggered()"), self, SLOT("open()"))
-
- saveAct = QAction(QIcon(":/images/save.png"), tr("&Save"), self)
- saveAct.setShortcuts(QKeySequence.Save)
- saveAct.setStatusTip(tr("Save the document to disk")")
- connect(saveAct, SIGNAL("triggered()"), self, SLOT("save()"))
-
- saveAsAct = QAction(tr("Save &As..."), self)
- saveAsAct.setShortcuts(QKeySequence.SaveAs)
- saveAsAct.setStatusTip(tr("Save the document under a name")")
- connect(saveAsAct, SIGNAL("triggered()"), self, SLOT("saveAs()"))
-
-//! [0]
- exitAct = QAction(tr("E&xit"), self)
- exitAct.setShortcut(tr("Ctrl+Q")")
- exitAct.setStatusTip(tr("Exit the application")")
- connect(exitAct, SIGNAL("triggered()"), qApp, SLOT("closeAllWindows()"))
-//! [0]
-
- cutAct = QAction(QIcon(":/images/cut.png"), tr("Cu&t"), self)
- cutAct.setShortcuts(QKeySequence.Cut)
- cutAct.setStatusTip(tr("Cut the current selection's contents to the "
- "clipboard")")
- connect(cutAct, SIGNAL("triggered()"), self, SLOT("cut()"))
-
- copyAct = QAction(QIcon(":/images/copy.png"), tr("&Copy"), self)
- copyAct.setShortcuts(QKeySequence.Copy)
- copyAct.setStatusTip(tr("Copy the current selection's contents to the "
- "clipboard")")
- connect(copyAct, SIGNAL("triggered()"), self, SLOT("copy()"))
-
- pasteAct = QAction(QIcon(":/images/paste.png"), tr("&Paste"), self)
- pasteAct.setShortcuts(QKeySequence.Paste)
- pasteAct.setStatusTip(tr("Paste the clipboard's contents into the current "
- "selection")")
- connect(pasteAct, SIGNAL("triggered()"), self, SLOT("paste()"))
-
- closeAct = QAction(tr("Cl&ose"), self)
- closeAct.setShortcut(tr("Ctrl+F4")")
- closeAct.setStatusTip(tr("Close the active window")")
- connect(closeAct, SIGNAL("triggered()"),
- mdiArea, SLOT("closeActiveSubWindow()"))
-
- closeAllAct = QAction(tr("Close &All"), self)
- closeAllAct.setStatusTip(tr("Close all the windows")")
- connect(closeAllAct, SIGNAL("triggered()"),
- mdiArea, SLOT("closeAllSubWindows()"))
-
- tileAct = QAction(tr("&Tile"), self)
- tileAct.setStatusTip(tr("Tile the windows")")
- connect(tileAct, SIGNAL("triggered()"), mdiArea, SLOT("tileSubWindows()"))
-
- cascadeAct = QAction(tr("&Cascade"), self)
- cascadeAct.setStatusTip(tr("Cascade the windows")")
- connect(cascadeAct, SIGNAL("triggered()"), mdiArea, SLOT("cascadeSubWindows()"))
-
- nextAct = QAction(tr("Ne&xt"), self)
- nextAct.setShortcuts(QKeySequence.NextChild)
- nextAct.setStatusTip(tr("Move the focus to the next window")")
- connect(nextAct, SIGNAL("triggered()"),
- mdiArea, SLOT("activateNextSubWindow()"))
-
- previousAct = QAction(tr("Pre&vious"), self)
- previousAct.setShortcuts(QKeySequence.PreviousChild)
- previousAct.setStatusTip(tr("Move the focus to the previous "
- "window")")
- connect(previousAct, SIGNAL("triggered()"),
- mdiArea, SLOT("activatePreviousSubWindow()"))
-
- separatorAct = QAction(self)
- separatorAct.setSeparator(True)
-
- aboutAct = QAction(tr("&About"), self)
- aboutAct.setStatusTip(tr("Show the application's About box")")
- connect(aboutAct, SIGNAL("triggered()"), self, SLOT("about()"))
-
- aboutQtAct = QAction(tr("About &Qt"), self)
- aboutQtAct.setStatusTip(tr("Show the Qt library's About box")")
- connect(aboutQtAct, SIGNAL("triggered()"), qApp, SLOT("aboutQt()"))
-
-
-def createMenus()
-
- fileMenu = menuBar().addMenu(tr("&File")")
- fileMenu.addAction(Act)
- fileMenu.addAction(openAct)
- fileMenu.addAction(saveAct)
- fileMenu.addAction(saveAsAct)
- fileMenu.addSeparator()
- QAction *action = fileMenu.addAction(tr("Switch layout direction")")
- connect(action, SIGNAL("triggered()"), self, SLOT("switchLayoutDirection()"))
- fileMenu.addAction(exitAct)
-
- editMenu = menuBar().addMenu(tr("&Edit")")
- editMenu.addAction(cutAct)
- editMenu.addAction(copyAct)
- editMenu.addAction(pasteAct)
-
- windowMenu = menuBar().addMenu(tr("&Window")")
- updateWindowMenu()
- connect(windowMenu, SIGNAL("aboutToShow()"), self, SLOT("updateWindowMenu()"))
-
- menuBar().addSeparator()
-
- helpMenu = menuBar().addMenu(tr("&Help")")
- helpMenu.addAction(aboutAct)
- helpMenu.addAction(aboutQtAct)
-
-
-def createToolBars()
-
- fileToolBar = addToolBar(tr("File")")
- fileToolBar.addAction(Act)
- fileToolBar.addAction(openAct)
- fileToolBar.addAction(saveAct)
-
- editToolBar = addToolBar(tr("Edit")")
- editToolBar.addAction(cutAct)
- editToolBar.addAction(copyAct)
- editToolBar.addAction(pasteAct)
-
-
-def createStatusBar()
-
- statusBar().showMessage(tr("Ready")")
-
-
-def readSettings()
-
- QSettings settings("Trolltech", "MDI Example")
- QPoint pos = settings.value("pos", QPoint(200, 200)").toPoint()
- QSize size = settings.value("size", QSize(400, 400)").toSize()
- move(pos)
- resize(size)
-
-
-def writeSettings()
-
- QSettings settings("Trolltech", "MDI Example")
- settings.setValue("pos", pos()")
- settings.setValue("size", size()")
-
-
-MdiChild *activeMdiChild()
-
- if (QMdiSubWindow *activeSubWindow = mdiArea.activeSubWindow()")
- return qobject_cast<MdiChild *>(activeSubWindow.widget()")
- return 0
-
-
-QMdiSubWindow *findMdiChild(const QString &fileName)
-
- QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath()
-
- foreach (QMdiSubWindow *window, mdiArea.subWindowList()")
- MdiChild *mdiChild = qobject_cast<MdiChild *>(window.widget()")
- if (mdiChild.currentFile() == canonicalFilePath)
- return window
-
- return 0
-
-
-def switchLayoutDirection()
-
- if (layoutDirection() == Qt.LeftToRight)
- qApp.setLayoutDirection(Qt.RightToLeft)
- else
- qApp.setLayoutDirection(Qt.LeftToRight)
-
-
-def setActiveSubWindow(QWidget *window)
-
- if (!window)
- return
- mdiArea.setActiveSubWindow(qobject_cast<QMdiSubWindow *>(window)")
-
diff --git a/sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.py b/sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.py
new file mode 100644
index 000000000..41f515847
--- /dev/null
+++ b/sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.py
@@ -0,0 +1,360 @@
+############################################################################
+##
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the examples of Qt for Python.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## BSD License Usage
+## Alternatively, you may use this file under the terms of the BSD license
+## as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in
+## the documentation and/or other materials provided with the
+## distribution.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+##
+## $QT_END_LICENSE$
+##
+############################################################################
+
+from PySide2.QtGui import *
+
+class QMdiSubWindow(QMainWindow):
+ def __init__(self, parent=None):
+ QMainWindow.__init__(self, parent)
+
+ mdiArea = QMdiArea()
+ mdiArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
+ mdiArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
+ setCentralWidget(mdiArea)
+ mdiArea.subWindowActivated[QMdiSubWindow].connect(updateMenus)
+ windowMapper = QSignalMapper(self)
+ windowMapper.mapped[QWidget].connect(setActiveSubWindow)
+
+ self.createActions()
+ self.createMenus()
+ self.createToolBars()
+ self.createStatusBar()
+ self.updateMenus()
+ self.readSettings()
+ self.setWindowTitle(tr("MDI"))
+ self.setUnifiedTitleAndToolBarOnMac(True)
+
+
+ def closeEvent(self, event):
+ mdiArea.closeAllSubWindows()
+ if self.activeMdiChild():
+ event.ignore()
+ else:
+ self.writeSettings()
+ event.accept()
+
+ def File(self):
+ child = self.createMdiChild()
+ child.File()
+ child.show()
+
+
+ def open(self):
+ fileName = QFileDialog.getOpenFileName(self)
+ if not fileName.isEmpty():
+ existing = self.findMdiChild(fileName)
+ if existing:
+ mdiArea.setActiveSubWindow(existing)
+ return
+
+ child = createMdiChild()
+ if child.loadFile(fileName):
+ statusBar().showMessage(tr("File loaded"), 2000)
+ child.show()
+ else:
+ child.close()
+
+ def save(self):
+ if self.activeMdiChild() and self.activeMdiChild().save():
+ self.statusBar().showMessage(tr("File saved"), 2000)
+
+ def saveAs(self):
+ if self.activeMdiChild() and self.activeMdiChild().saveAs():
+ self.statusBar().showMessage(tr("File saved"), 2000)
+
+ def cut(self):
+ if self.activeMdiChild():
+ self.activeMdiChild().cut()
+
+ def copy(self):
+ if self.activeMdiChild():
+ activeMdiChild().copy()
+
+ def paste(self):
+ if self.activeMdiChild():
+ activeMdiChild().paste()
+
+ def about(self):
+ QMessageBox.about(self, tr("About MDI"),
+ tr("The <b>MDI</b> example demonstrates how to write multiple "
+ "document interface applications using Qt."))
+
+ def updateMenus(self):
+ hasMdiChild = (activeMdiChild() != 0)
+ self.saveAct.setEnabled(hasMdiChild)
+ self.saveAsAct.setEnabled(hasMdiChild)
+ self.pasteAct.setEnabled(hasMdiChild)
+ self.closeAct.setEnabled(hasMdiChild)
+ self.closeAllAct.setEnabled(hasMdiChild)
+ self.tileAct.setEnabled(hasMdiChild)
+ self.cascadeAct.setEnabled(hasMdiChild)
+ self.nextAct.setEnabled(hasMdiChild)
+ self.previousAct.setEnabled(hasMdiChild)
+ self.separatorAct.setVisible(hasMdiChild)
+
+ hasSelection = (self.activeMdiChild() and
+ self.activeMdiChild().textCursor().hasSelection())
+ self.cutAct.setEnabled(hasSelection)
+ self.copyAct.setEnabled(hasSelection)
+
+ def updateWindowMenu(self):
+ self.windowMenu.clear()
+ self.windowMenu.addAction(closeAct)
+ self.windowMenu.addAction(closeAllAct)
+ self.windowMenu.addSeparator()
+ self.windowMenu.addAction(tileAct)
+ self.windowMenu.addAction(cascadeAct)
+ self.windowMenu.addSeparator()
+ self.windowMenu.addAction(nextAct)
+ self.windowMenu.addAction(previousAct)
+ self.windowMenu.addAction(separatorAct)
+
+ windows = mdiArea.subWindowList()
+ separatorAct.setVisible(not windows.isEmpty())
+
+ for i in range(0, windows.size()):
+ child = windows.at(i).widget()
+
+ text = ""
+ if i < 9:
+ text = "{} {}".format(i + 1, child.userFriendlyCurrentFile())
+ else:
+ text = "{} {}".format(i + 1, child.userFriendlyCurrentFile())
+
+ action = windowMenu.addAction(text)
+ action.setCheckable(True)
+ action.setChecked(child == activeMdiChild())
+ action.triggered.connect(windowMapper.map)
+ windowMapper.setMapping(action, windows.at(i))
+
+ createMdiChild = MdiChild()
+
+ child = MdiChild()
+ mdiArea.addSubWindow(child)
+
+ child.copyAvailable[bool].connect(cutAct.setEnabled)
+ child.copyAvailable[bool].connect(copyAct.setEnabled)
+
+ return child
+
+
+ def createActions(self):
+
+ Act = QAction(QIcon(":/images/new.png"), tr("&New"), self)
+ Act.setShortcuts(QKeySequence.New)
+ Act.setStatusTip(tr("Create a new file"))
+ Act.triggered.connect(self.newFile)
+
+ openAct = QAction(QIcon(":/images/open.png"), tr("&Open..."), self)
+ openAct.setShortcuts(QKeySequence.Open)
+ openAct.setStatusTip(tr("Open an existing file"))
+ openAct.triggered.connect(self.open)
+
+ saveAct = QAction(QIcon(":/images/save.png"), tr("&Save"), self)
+ saveAct.setShortcuts(QKeySequence.Save)
+ saveAct.setStatusTip(tr("Save the document to disk"))
+ saveAct.triggered.connect(self.save)
+
+ saveAsAct = QAction(tr("Save &As..."), self)
+ saveAsAct.setShortcuts(QKeySequence.SaveAs)
+ saveAsAct.setStatusTip(tr("Save the document under a name"))
+ saveAsAct.triggered.connect(self.saveAs)
+
+//! [0]
+ exitAct = QAction(tr("E&xit"), self)
+ exitAct.setShortcut(tr("Ctrl+Q"))
+ exitAct.setStatusTip(tr("Exit the application"))
+ exitAct.triggered.connect(qApp.closeAllWindows)
+//! [0]
+
+ cutAct = QAction(QIcon(":/images/cut.png"), tr("Cu&t"), self)
+ cutAct.setShortcuts(QKeySequence.Cut)
+ cutAct.setStatusTip(tr("Cut the current selection's contents to the "
+ "clipboard"))
+ cutAct.triggered.connect(self.cut)
+
+ copyAct = QAction(QIcon(":/images/copy.png"), tr("&Copy"), self)
+ copyAct.setShortcuts(QKeySequence.Copy)
+ copyAct.setStatusTip(tr("Copy the current selection's contents to the "
+ "clipboard"))
+ copyAct.triggered.connect(self.copy)
+
+ pasteAct = QAction(QIcon(":/images/paste.png"), tr("&Paste"), self)
+ pasteAct.setShortcuts(QKeySequence.Paste)
+ pasteAct.setStatusTip(tr("Paste the clipboard's contents into the current "
+ "selection"))
+ pasteAct.triggered.connect(self.paste)
+
+ closeAct = QAction(tr("Cl&ose"), self)
+ closeAct.setShortcut(tr("Ctrl+F4"))
+ closeAct.setStatusTip(tr("Close the active window"))
+ closeAct.triggered.connect(mdiArea.closeActiveSubWindow)
+
+ closeAllAct = QAction(tr("Close &All"), self)
+ closeAllAct.setStatusTip(tr("Close all the windows"))
+ closeAllAct.triggered.connect(mdiArea.closeAllSubWindows)
+
+ tileAct = QAction(tr("&Tile"), self)
+ tileAct.setStatusTip(tr("Tile the windows"))
+ tileAct.triggered.connect(mdiArea.tileSubWindows)
+
+ cascadeAct = QAction(tr("&Cascade"), self)
+ cascadeAct.setStatusTip(tr("Cascade the windows"))
+ cascadeAct.triggered.connect(mdiArea.cascadeSubWindows)
+
+ nextAct = QAction(tr("Ne&xt"), self)
+ nextAct.setShortcuts(QKeySequence.NextChild)
+ nextAct.setStatusTip(tr("Move the focus to the next window"))
+ nextAct.triggered.connect(mdiArea.activateNextSubWindow)
+
+ previousAct = QAction(tr("Pre&vious"), self)
+ previousAct.setShortcuts(QKeySequence.PreviousChild)
+ previousAct.setStatusTip(tr("Move the focus to the previous "
+ "window"))
+ previousAct.triggered.connect(mdiArea.activatePreviousSubWindow)
+
+ separatorAct = QAction(self)
+ separatorAct.setSeparator(True)
+
+ aboutAct = QAction(tr("&About"), self)
+ aboutAct.setStatusTip(tr("Show the application's About box"))
+ aboutAct.triggered.connect(self.about)
+
+ aboutQtAct = QAction(tr("About &Qt"), self)
+ aboutQtAct.setStatusTip(tr("Show the Qt library's About box"))
+ aboutQtAct.triggered.connect(qApp.aboutQt)
+
+
+ def createMenus(self):
+
+ fileMenu = menuBar().addMenu(tr("&File"))
+ fileMenu.addAction(Act)
+ fileMenu.addAction(openAct)
+ fileMenu.addAction(saveAct)
+ fileMenu.addAction(saveAsAct)
+ fileMenu.addSeparator()
+ action = fileMenu.addAction(tr("Switch layout direction"))
+ action.triggered.connect(self.switchLayoutDirection)
+ fileMenu.addAction(exitAct)
+
+ editMenu = menuBar().addMenu(tr("&Edit"))
+ editMenu.addAction(cutAct)
+ editMenu.addAction(copyAct)
+ editMenu.addAction(pasteAct)
+
+ windowMenu = menuBar().addMenu(tr("&Window"))
+ updateWindowMenu()
+ windowMenu.aboutToShow.connect(self.updateWindowMenu)
+
+ menuBar().addSeparator()
+
+ helpMenu = menuBar().addMenu(tr("&Help"))
+ helpMenu.addAction(aboutAct)
+ helpMenu.addAction(aboutQtAct)
+
+
+ def createToolBars(self):
+ fileToolBar = addToolBar(tr("File"))
+ fileToolBar.addAction(Act)
+ fileToolBar.addAction(openAct)
+ fileToolBar.addAction(saveAct)
+
+ editToolBar = addToolBar(tr("Edit"))
+ editToolBar.addAction(cutAct)
+ editToolBar.addAction(copyAct)
+ editToolBar.addAction(pasteAct)
+
+
+ def createStatusBar(self):
+ statusBar().showMessage(tr("Ready"))
+
+
+ def readSettings(self):
+ settings = QSettings("Trolltech", "MDI Example")
+ QPoint pos = settings.value("pos", QPoint(200, 200)").toPoint()
+ QSize size = settings.value("size", QSize(400, 400)").toSize()
+ move(pos)
+ resize(size)
+
+ def writeSettings(self):
+ QSettings settings("Trolltech", "MDI Example")
+ settings.setValue("pos", pos()")
+ settings.setValue("size", size()")
+
+
+ activeMdiChild = MdiChild()
+ activeSubWindow = mdiArea.activeSubWindow()
+ if activeSubWindow:
+ return activeSubWindow.widget()
+ return 0
+
+
+ def findMdiChild(self, fileName):
+
+ canonicalFilePath = QFileInfo(fileName).canonicalFilePath()
+
+ for window in mdiArea.subWindowList():
+ mdiChild = window.widget()
+ if mdiChild.currentFile() == canonicalFilePath:
+ return window
+ return 0
+
+
+ def switchLayoutDirection(self)
+ if layoutDirection() == Qt.LeftToRight:
+ qApp.setLayoutDirection(Qt.RightToLeft)
+ else:
+ qApp.setLayoutDirection(Qt.LeftToRight)
+
+
+ def setActiveSubWindow(self, window):
+ if not window:
+ return
+ mdiArea.setActiveSubWindow(window)
diff --git a/sources/pyside2/doc/codesnippets/examples/mainwindows/menus/mainwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/menus/mainwindow.py
index 6ed5f5466..6505f1f1a 100644
--- a/sources/pyside2/doc/codesnippets/examples/mainwindows/menus/mainwindow.cpp
+++ b/sources/pyside2/doc/codesnippets/examples/mainwindows/menus/mainwindow.py
@@ -196,63 +196,63 @@ def createActions(self):
Act = new QAction(tr("&New"), self)
Act.setShortcuts(QKeySequence.New)
Act.setStatusTip(tr("Create a new file"))
- connect(Act, SIGNAL("triggered()"), self, SLOT("newFile()"))
+ Act.triggered.connect(newFile)
//! [4]
openAct = QAction(tr("&Open..."), self)
openAct.setShortcuts(QKeySequence.Open)
openAct.setStatusTip(tr("Open an existing file"))
- connect(openAct, SIGNAL("triggered()"), self, SLOT("open()"))
+ openAct.triggered.connect(open)
//! [5]
saveAct = QAction(tr("&Save"), self)
saveAct.setShortcuts(QKeySequence.Save)
saveAct.setStatusTip(tr("Save the document to disk"))
- connect(saveAct, SIGNAL("triggered()"), self, SLOT("save()"))
+ saveAct.triggered.connect(save)
printAct = QAction(tr("&Print..."), self)
printAct.setShortcuts(QKeySequence.Print)
printAct.setStatusTip(tr("Print the document"))
- connect(printAct, SIGNAL("triggered()"), self, SLOT("print_()"))
+ printAct.triggered.connect(print_)
exitAct = QAction(tr("E&xit"), self)
exitAct.setShortcut(tr("Ctrl+Q"))
exitAct.setStatusTip(tr("Exit the application"))
- connect(exitAct, SIGNAL("triggered()"), self, SLOT("close()"))
+ exitAct.triggered.connect(close)
undoAct = QAction(tr("&Undo"), self)
undoAct.setShortcuts(QKeySequence.Undo)
undoAct.setStatusTip(tr("Undo the last operation"))
- connect(undoAct, SIGNAL("triggered()"), self, SLOT("undo()"))
+ undoAct.triggered.connect(undo)
redoAct = QAction(tr("&Redo"), self)
redoAct.setShortcuts(QKeySequence.Redo)
redoAct.setStatusTip(tr("Redo the last operation"))
- connect(redoAct, SIGNAL("triggered()"), self, SLOT("redo()"))
+ redoAct.triggered.connect(redo)
cutAct = QAction(tr("Cu&t"), self)
cutAct.setShortcuts(QKeySequence.Cut)
cutAct.setStatusTip(tr("Cut the current selection's contents to the "
"clipboard"))
- connect(cutAct, SIGNAL("triggered()"), self, SLOT("cut()"))
+ cutAct.triggered.connect(cut)
copyAct = QAction(tr("&Copy"), self)
copyAct.setShortcut(tr("Ctrl+C"))
copyAct.setStatusTip(tr("Copy the current selection's contents to the "
"clipboard"))
- connect(copyAct, SIGNAL("triggered()"), self, SLOT("copy()"))
+ copyAct.triggered.connect(copy)
pasteAct = QAction(tr("&Paste"), self)
pasteAct.setShortcuts(QKeySequence.Paste)
pasteAct.setStatusTip(tr("Paste the clipboard's contents into the current "
"selection"))
- connect(pasteAct, SIGNAL("triggered()"), self, SLOT("paste()"))
+ pasteAct.triggered.connect(paste)
boldAct = QAction(tr("&Bold"), self)
boldAct.setCheckable(True)
boldAct.setShortcut(tr("Ctrl+B"))
boldAct.setStatusTip(tr("Make the text bold"))
- connect(boldAct, SIGNAL("triggered()"), self, SLOT("bold()"))
+ boldAct.triggered.connect(bold)
QFont boldFont = boldAct.font()
boldFont.setBold(True)
@@ -262,7 +262,7 @@ def createActions(self):
italicAct.setCheckable(True)
italicAct.setShortcut(tr("Ctrl+I"))
italicAct.setStatusTip(tr("Make the text italic"))
- connect(italicAct, SIGNAL("triggered()"), self, SLOT("italic()"))
+ italicAct.triggered.connect(italic)
QFont italicFont = italicAct.font()
italicFont.setItalic(True)
@@ -271,45 +271,44 @@ def createActions(self):
setLineSpacingAct = QAction(tr("Set &Line Spacing..."), self)
setLineSpacingAct.setStatusTip(tr("Change the gap between the lines of a "
"paragraph"))
- connect(setLineSpacingAct, SIGNAL("triggered()"), self, SLOT("setLineSpacing()"))
+ setLineSpacingAct.triggered.connect(setLineSpacing)
setParagraphSpacingAct = QAction(tr("Set &Paragraph Spacing..."), self)
setLineSpacingAct.setStatusTip(tr("Change the gap between paragraphs"))
- connect(setParagraphSpacingAct, SIGNAL("triggered()"),
- self, SLOT("setParagraphSpacing()"))
+ setParagraphSpacingAct.triggered.connect(setParagraphSpacing)
aboutAct = QAction(tr("&About"), self)
aboutAct.setStatusTip(tr("Show the application's About box"))
- connect(aboutAct, SIGNAL("triggered()"), self, SLOT("about()"))
+ aboutAct.triggered.connect(about)
aboutQtAct = QAction(tr("About &Qt"), self)
aboutQtAct.setStatusTip(tr("Show the Qt library's About box"))
- connect(aboutQtAct, SIGNAL("triggered()"), qApp, SLOT("aboutQt()"))
- connect(aboutQtAct, SIGNAL("triggered()"), self, SLOT("aboutQt()"))
+ aboutQtAct.triggered.connect(qApp.aboutQt)
+ aboutQtAct.triggered.connect(aboutQt)
leftAlignAct = QAction(tr("&Left Align"), self)
leftAlignAct.setCheckable(True)
leftAlignAct.setShortcut(tr("Ctrl+L"))
leftAlignAct.setStatusTip(tr("Left align the selected text"))
- connect(leftAlignAct, SIGNAL("triggered()"), self, SLOT("leftAlign()"))
+ leftAlignAct.triggered.connect(leftAlign)
rightAlignAct = QAction(tr("&Right Align"), self)
rightAlignAct.setCheckable(True)
rightAlignAct.setShortcut(tr("Ctrl+R"))
rightAlignAct.setStatusTip(tr("Right align the selected text"))
- connect(rightAlignAct, SIGNAL("triggered()"), self, SLOT("rightAlign()"))
+ rightAlignAct.triggered.connect(rightAlign)
justifyAct = QAction(tr("&Justify"), self)
justifyAct.setCheckable(True)
justifyAct.setShortcut(tr("Ctrl+J"))
justifyAct.setStatusTip(tr("Justify the selected text"))
- connect(justifyAct, SIGNAL("triggered()"), self, SLOT("justify()"))
+ justifyAct.triggered.connect(justify)
centerAct = QAction(tr("&Center"), self)
centerAct.setCheckable(True)
centerAct.setShortcut(tr("Ctrl+E"))
centerAct.setStatusTip(tr("Center the selected text"))
- connect(centerAct, SIGNAL("triggered()"), self, SLOT("center()"))
+ centerAct.triggered.connect(center)
//! [6] //! [7]
alignmentGroup = QActionGroup(self)
diff --git a/sources/pyside2/doc/codesnippets/examples/widgets/spinboxes/window.cpp b/sources/pyside2/doc/codesnippets/examples/widgets/spinboxes/window.py
index 7eace108a..40fe28bf1 100644
--- a/sources/pyside2/doc/codesnippets/examples/widgets/spinboxes/window.cpp
+++ b/sources/pyside2/doc/codesnippets/examples/widgets/spinboxes/window.py
@@ -147,8 +147,7 @@ def createDateTimeEdits(self):
formatComboBox.addItem("hh:mm ap")
//! [9] //! [10]
- connect(formatComboBox, SIGNAL("activated(const QString &)"),
- self, SLOT("setFormatString(const QString &)"))
+ formatComboBox.activated[str].connect(setFormatString)
//! [10]
setFormatString(formatComboBox.currentText())
@@ -174,12 +173,12 @@ def setFormatString(self, formatString):
meetingEdit.setDateRange(QDate(2004, 11, 1), QDate(2005, 11, 30))
meetingLabel.setText(tr("Meeting date (between %0 and %1):")
.arg(meetingEdit.minimumDate().toString(Qt.ISODate))
- .arg(meetingEdit.maximumDate().toString(Qt.ISODate)))
+ .arg(meetingEdit.maximumDate().toString(Qt.ISODate)))
else:
meetingEdit.setTimeRange(QTime(0, 7, 20, 0), QTime(21, 0, 0, 0))
meetingLabel.setText(tr("Meeting time (between %0 and %1):")
.arg(meetingEdit.minimumTime().toString(Qt.ISODate))
- .arg(meetingEdit.maximumTime().toString(Qt.ISODate)))
+ .arg(meetingEdit.maximumTime().toString(Qt.ISODate)))
//! [13]
//! [14]
@@ -222,9 +221,8 @@ def createDoubleSpinBoxes():
priceSpinBox.setPrefix("$")
priceSpinBox.setValue(99.99)
- connect(precisionSpinBox, SIGNAL("valueChanged(int)"),
+ precisionSpinBox.valueChanged[int].connect(changePrecision)
//! [17]
- self, SLOT("changePrecision(int))")
//! [18]
spinBoxLayout = QVBoxLayout()