diff options
Diffstat (limited to 'sources/pyside2/doc/codesnippets/examples/mainwindows')
-rw-r--r-- | sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.h | 112 | ||||
-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/menus/mainwindow.cpp) | 43 | ||||
-rw-r--r-- | sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.cpp | 381 | ||||
-rw-r--r-- | sources/pyside2/doc/codesnippets/examples/mainwindows/mdi/mainwindow.py | 360 | ||||
-rw-r--r-- | sources/pyside2/doc/codesnippets/examples/mainwindows/menus/mainwindow.py (renamed from sources/pyside2/doc/codesnippets/examples/mainwindows/mainwindow.cpp) | 43 |
7 files changed, 558 insertions, 473 deletions
diff --git a/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.h b/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.h new file mode 100644 index 000000000..bdb7bcf22 --- /dev/null +++ b/sources/pyside2/doc/codesnippets/examples/mainwindows/application/mainwindow.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples 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 (QAction, QApplication, QMainWindow, QMenu, + QPlainTextEdit, QSessionManager) + + +//! [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 + + def save(self): + pass + + def saveAs(self): + pass + + def about(self): + pass + + def documentWasModified(self): + pass + # Enable this only if QT_NO_SESSIONMANAGER is not defined + # def commitData(self): + # pass + + 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/menus/mainwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/mainwindow.py index 6ed5f5466..b0bbed810 100644 --- a/sources/pyside2/doc/codesnippets/examples/mainwindows/menus/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/mainwindow.cpp b/sources/pyside2/doc/codesnippets/examples/mainwindows/menus/mainwindow.py index 6ed5f5466..6505f1f1a 100644 --- a/sources/pyside2/doc/codesnippets/examples/mainwindows/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) |