aboutsummaryrefslogtreecommitdiffstats
path: root/examples/sql
diff options
context:
space:
mode:
Diffstat (limited to 'examples/sql')
-rw-r--r--examples/sql/books/bookdelegate.py66
-rw-r--r--examples/sql/books/books.qrc3
-rw-r--r--examples/sql/books/bookwindow.py73
-rw-r--r--examples/sql/books/createdb.py64
-rw-r--r--examples/sql/books/doc/books.pngbin0 -> 59045 bytes
-rw-r--r--examples/sql/books/doc/books.rst11
-rw-r--r--examples/sql/books/images/star-filled.svg1
-rw-r--r--examples/sql/books/images/star.pngbin782 -> 0 bytes
-rw-r--r--examples/sql/books/images/star.svg1
-rw-r--r--examples/sql/books/main.py47
-rw-r--r--examples/sql/books/rc_books.py144
-rw-r--r--examples/sql/books/ui_bookwindow.py22
-rw-r--r--examples/sql/relationaltablemodel/connection.py18
-rw-r--r--examples/sql/relationaltablemodel/relationaltablemodel.py77
14 files changed, 263 insertions, 264 deletions
diff --git a/examples/sql/books/bookdelegate.py b/examples/sql/books/bookdelegate.py
index f7e219ad6..78295adf1 100644
--- a/examples/sql/books/bookdelegate.py
+++ b/examples/sql/books/bookdelegate.py
@@ -1,48 +1,11 @@
-#############################################################################
-##
-## Copyright (C) 2019 The Qt Company Ltd.
-## Contact: http://www.qt.io/licensing/
-##
-## This file is part of the Qt for Python examples of the Qt Toolkit.
-##
-## $QT_BEGIN_LICENSE:BSD$
-## 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) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import copy
-from PySide2.QtSql import QSqlRelationalDelegate
-from PySide2.QtWidgets import QSpinBox, QStyle
-from PySide2.QtGui import QPixmap, QPalette
-from PySide2.QtCore import QEvent, QSize, Qt
+from PySide6.QtSql import QSqlRelationalDelegate
+from PySide6.QtWidgets import QSpinBox, QStyle
+from PySide6.QtGui import QPixmap, QPalette
+from PySide6.QtCore import QEvent, QSize, Qt
class BookDelegate(QSqlRelationalDelegate):
@@ -50,7 +13,8 @@ class BookDelegate(QSqlRelationalDelegate):
def __init__(self, parent=None):
QSqlRelationalDelegate.__init__(self, parent)
- self.star = QPixmap(":/images/star.png")
+ self.star = QPixmap(":/images/star.svg")
+ self.star_filled = QPixmap(":/images/star-filled.svg")
def paint(self, painter, option, index):
""" Paint the items in the table.
@@ -80,19 +44,19 @@ class BookDelegate(QSqlRelationalDelegate):
if option.state & QStyle.State_Selected:
painter.fillRect(option.rect,
- option.palette.color(color_group, QPalette.Highlight))
+ option.palette.color(color_group, QPalette.Highlight))
rating = model.data(index, Qt.DisplayRole)
width = self.star.width()
height = self.star.height()
x = option.rect.x()
y = option.rect.y() + (option.rect.height() / 2) - (height / 2)
- for i in range(rating):
- painter.drawPixmap(x, y, self.star)
+ for i in range(5):
+ if i < rating:
+ painter.drawPixmap(x, y, self.star_filled)
+ else:
+ painter.drawPixmap(x, y, self.star)
x += width
- # Since we draw the grid ourselves:
- self.drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1))
-
pen = painter.pen()
painter.setPen(option.palette.color(QPalette.Mid))
painter.drawLine(option.rect.bottomLeft(), option.rect.bottomRight())
@@ -112,7 +76,7 @@ class BookDelegate(QSqlRelationalDelegate):
return False
if event.type() == QEvent.MouseButtonPress:
- mouse_pos = event.pos()
+ mouse_pos = event.position()
new_stars = int(0.7 + (mouse_pos.x() - option.rect.x()) / self.star.width())
stars = max(0, min(new_stars, 5))
model.setData(index, stars)
diff --git a/examples/sql/books/books.qrc b/examples/sql/books/books.qrc
index d6ad21337..a52ee381b 100644
--- a/examples/sql/books/books.qrc
+++ b/examples/sql/books/books.qrc
@@ -1,5 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
- <file>images/star.png</file>
+ <file>images/star.svg</file>
+ <file>images/star-filled.svg</file>
</qresource>
</RCC>
diff --git a/examples/sql/books/bookwindow.py b/examples/sql/books/bookwindow.py
index 31d2a055f..7f9e0f94b 100644
--- a/examples/sql/books/bookwindow.py
+++ b/examples/sql/books/bookwindow.py
@@ -1,50 +1,11 @@
-#############################################################################
-##
-## Copyright (C) 2019 The Qt Company Ltd.
-## Contact: http://www.qt.io/licensing/
-##
-## This file is part of the Qt for Python examples of the Qt Toolkit.
-##
-## $QT_BEGIN_LICENSE:BSD$
-## 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 __future__ import print_function, absolute_import
-
-from PySide2.QtWidgets import (QAbstractItemView, QDataWidgetMapper,
- QHeaderView, QMainWindow, QMessageBox)
-from PySide2.QtGui import QKeySequence
-from PySide2.QtSql import QSqlRelation, QSqlRelationalTableModel, QSqlTableModel
-from PySide2.QtCore import Qt, Slot
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+from PySide6.QtWidgets import (QAbstractItemView, QDataWidgetMapper,
+ QHeaderView, QMainWindow, QMessageBox)
+from PySide6.QtGui import QKeySequence
+from PySide6.QtSql import QSqlRelation, QSqlRelationalTableModel, QSqlTableModel
+from PySide6.QtCore import Qt, Slot
import createdb
from ui_bookwindow import Ui_BookWindow
from bookdelegate import BookDelegate
@@ -54,10 +15,10 @@ class BookWindow(QMainWindow, Ui_BookWindow):
"""A window to show the books available"""
def __init__(self):
- QMainWindow.__init__(self)
+ super().__init__()
self.setupUi(self)
- #Initialize db
+ # Initialize db
createdb.init_db()
model = QSqlRelationalTableModel(self.bookTable)
@@ -97,7 +58,7 @@ class BookWindow(QMainWindow, Ui_BookWindow):
# Lock and prohibit resizing of the width of the rating column:
self.bookTable.horizontalHeader().setSectionResizeMode(model.fieldIndex("rating"),
- QHeaderView.ResizeToContents)
+ QHeaderView.ResizeToContents)
mapper = QDataWidgetMapper(self)
mapper.setModel(model)
@@ -114,24 +75,24 @@ class BookWindow(QMainWindow, Ui_BookWindow):
self.bookTable.setCurrentIndex(model.index(0, 0))
self.create_menubar()
- def showError(err):
+ def showError(self, err):
QMessageBox.critical(self, "Unable to initialize Database",
- "Error initializing database: " + err.text())
+ f"Error initializing database: {err.text()}")
def create_menubar(self):
file_menu = self.menuBar().addMenu(self.tr("&File"))
quit_action = file_menu.addAction(self.tr("&Quit"))
- quit_action.triggered.connect(qApp.quit)
+ quit_action.triggered.connect(qApp.quit) # noqa: F821
help_menu = self.menuBar().addMenu(self.tr("&Help"))
about_action = help_menu.addAction(self.tr("&About"))
about_action.setShortcut(QKeySequence.HelpContents)
about_action.triggered.connect(self.about)
aboutQt_action = help_menu.addAction("&About Qt")
- aboutQt_action.triggered.connect(qApp.aboutQt)
+ aboutQt_action.triggered.connect(qApp.aboutQt) # noqa: F821
@Slot()
def about(self):
QMessageBox.about(self, self.tr("About Books"),
- self.tr("<p>The <b>Books</b> example shows how to use Qt SQL classes "
- "with a model/view framework."))
+ self.tr("<p>The <b>Books</b> example shows how to use Qt SQL classes "
+ "with a model/view framework."))
diff --git a/examples/sql/books/createdb.py b/examples/sql/books/createdb.py
index f8739b4d0..5ee0f148e 100644
--- a/examples/sql/books/createdb.py
+++ b/examples/sql/books/createdb.py
@@ -1,67 +1,32 @@
-#############################################################################
-##
-## Copyright (C) 2019 The Qt Company Ltd.
-## Contact: http://www.qt.io/licensing/
-##
-## This file is part of the Qt for Python examples of the Qt Toolkit.
-##
-## $QT_BEGIN_LICENSE:BSD$
-## 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.QtSql import QSqlDatabase, QSqlQuery
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+from PySide6.QtSql import QSqlDatabase, QSqlQuery
from datetime import date
+
def add_book(q, title, year, authorId, genreId, rating):
q.addBindValue(title)
q.addBindValue(year)
q.addBindValue(authorId)
q.addBindValue(genreId)
q.addBindValue(rating)
- q.exec_()
+ q.exec()
def add_genre(q, name):
q.addBindValue(name)
- q.exec_()
+ q.exec()
return q.lastInsertId()
def add_author(q, name, birthdate):
q.addBindValue(name)
q.addBindValue(str(birthdate))
- q.exec_()
+ q.exec()
return q.lastInsertId()
+
BOOKS_SQL = """
create table books(id integer primary key, title varchar, author integer,
genre integer, year integer, rating integer)
@@ -83,6 +48,7 @@ INSERT_BOOK_SQL = """
values(?, ?, ?, ?, ?)
"""
+
def init_db():
"""
init_db()
@@ -100,21 +66,21 @@ def init_db():
check(db.open)
q = QSqlQuery()
- check(q.exec_, BOOKS_SQL)
- check(q.exec_, AUTHORS_SQL)
- check(q.exec_, GENRES_SQL)
+ check(q.exec, BOOKS_SQL)
+ check(q.exec, AUTHORS_SQL)
+ check(q.exec, GENRES_SQL)
check(q.prepare, INSERT_AUTHOR_SQL)
asimovId = add_author(q, "Isaac Asimov", date(1920, 2, 1))
greeneId = add_author(q, "Graham Greene", date(1904, 10, 2))
pratchettId = add_author(q, "Terry Pratchett", date(1948, 4, 28))
- check(q.prepare,INSERT_GENRE_SQL)
+ check(q.prepare, INSERT_GENRE_SQL)
sfiction = add_genre(q, "Science Fiction")
fiction = add_genre(q, "Fiction")
fantasy = add_genre(q, "Fantasy")
- check(q.prepare,INSERT_BOOK_SQL)
+ check(q.prepare, INSERT_BOOK_SQL)
add_book(q, "Foundation", 1951, asimovId, sfiction, 3)
add_book(q, "Foundation and Empire", 1952, asimovId, sfiction, 4)
add_book(q, "Second Foundation", 1953, asimovId, sfiction, 3)
diff --git a/examples/sql/books/doc/books.png b/examples/sql/books/doc/books.png
new file mode 100644
index 000000000..102395155
--- /dev/null
+++ b/examples/sql/books/doc/books.png
Binary files differ
diff --git a/examples/sql/books/doc/books.rst b/examples/sql/books/doc/books.rst
new file mode 100644
index 000000000..cb8edc2ac
--- /dev/null
+++ b/examples/sql/books/doc/books.rst
@@ -0,0 +1,11 @@
+SQL Books Example
+=================
+
+Shows how to use Qt SQL classes with a model/view framework.
+
+The Books example shows how Qt's SQL classes can be used with the model/view
+framework to create rich user interfaces for information stored in a database.
+
+.. image:: books.png
+ :width: 400
+ :alt: SQL Books Screenshot
diff --git a/examples/sql/books/images/star-filled.svg b/examples/sql/books/images/star-filled.svg
new file mode 100644
index 000000000..8a2aee27f
--- /dev/null
+++ b/examples/sql/books/images/star-filled.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="#0d0d0d"><path d="M8.41 18.138L12 15.845l3.59 2.323-.94-4.345 3.162-2.897-4.159-.392L12 6.43l-1.652 4.073-4.159.392 3.162 2.927-.94 4.315zm-1.346 3.696a1.04 1.04 0 0 1-1.567-1.104l1.318-6.033-4.476-4.11c-.665-.611-.293-1.726.604-1.808l5.866-.539 2.229-5.587c.348-.872 1.575-.872 1.923 0l2.229 5.587 5.866.539c.897.082 1.269 1.197.604 1.808l-4.476 4.11 1.318 6.033a1.04 1.04 0 0 1-1.567 1.104L12 18.681l-4.935 3.153z"/><path d="M12 5l-1.796 5.528H4.392l4.702 3.416-1.796 5.528L12 16.056l4.702 3.416-1.796-5.528 4.702-3.416h-5.812L12 5z"/></svg>
diff --git a/examples/sql/books/images/star.png b/examples/sql/books/images/star.png
deleted file mode 100644
index 87f4464bd..000000000
--- a/examples/sql/books/images/star.png
+++ /dev/null
Binary files differ
diff --git a/examples/sql/books/images/star.svg b/examples/sql/books/images/star.svg
new file mode 100644
index 000000000..d959abc18
--- /dev/null
+++ b/examples/sql/books/images/star.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path d="M8.41 18.138L12 15.845l3.59 2.323-.94-4.345 3.162-2.897-4.159-.392L12 6.43l-1.652 4.073-4.159.392 3.162 2.927-.94 4.315zm-1.346 3.696a1.04 1.04 0 0 1-1.567-1.104l1.318-6.033-4.476-4.11c-.665-.611-.293-1.726.604-1.808l5.866-.539 2.229-5.587c.348-.872 1.575-.872 1.923 0l2.229 5.587 5.866.539c.897.082 1.269 1.197.604 1.808l-4.476 4.11 1.318 6.033a1.04 1.04 0 0 1-1.567 1.104L12 18.681l-4.935 3.153z" fill="#0d0d0d"/></svg>
diff --git a/examples/sql/books/main.py b/examples/sql/books/main.py
index 50d2c0d6b..025b55884 100644
--- a/examples/sql/books/main.py
+++ b/examples/sql/books/main.py
@@ -1,47 +1,10 @@
-#############################################################################
-##
-## Copyright (C) 2019 The Qt Company Ltd.
-## Contact: http://www.qt.io/licensing/
-##
-## This file is part of the Qt for Python examples of the Qt Toolkit.
-##
-## $QT_BEGIN_LICENSE:BSD$
-## 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) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import sys
-from PySide2.QtWidgets import QApplication
+from PySide6.QtWidgets import QApplication
from bookwindow import BookWindow
-import rc_books
+import rc_books # noqa: F401
if __name__ == "__main__":
app = QApplication([])
@@ -50,4 +13,4 @@ if __name__ == "__main__":
window.resize(800, 600)
window.show()
- sys.exit(app.exec_())
+ sys.exit(app.exec())
diff --git a/examples/sql/books/rc_books.py b/examples/sql/books/rc_books.py
index 6f2cbbeb6..123d50de8 100644
--- a/examples/sql/books/rc_books.py
+++ b/examples/sql/books/rc_books.py
@@ -1,62 +1,86 @@
# Resource object code (Python 3)
# Created by: object code
-# Created by: The Resource Compiler for Qt version 5.14.0
+# Created by: The Resource Compiler for Qt version 6.6.1
# WARNING! All changes made in this file will be lost!
-from PySide2 import QtCore
+from PySide6 import QtCore
qt_resource_data = b"\
-\x00\x00\x03\x0e\
-\x89\
-PNG\x0d\x0a\x1a\x0a\x00\x00\x00\x0dIHDR\x00\
-\x00\x00\x10\x00\x00\x00\x10\x08\x06\x00\x00\x00\x1f\xf3\xffa\
-\x00\x00\x00\x09pHYs\x00\x00\x0b\x11\x00\x00\x0b\x11\
-\x01\x7fd_\x91\x00\x00\x00\x07tIME\x07\xd4\x09\
-\x03\x12\x11\x08\x18~\xe5:\x00\x00\x00\x06bKGD\
-\x00\xff\x00\xff\x00\xff\xa0\xbd\xa7\x93\x00\x00\x02\x9bID\
-AT8\xcbc\x98:c\x1e#:\xe6\xe5d\xcf\x17\
-\x12\x12\x16\xc4&\x87\x8e\x19\xb0\x09v\xc6\x18\xb7x\xea\
-\x8b\xcd\x9c=o\x09i\x06,X4\x8f\xf1\xd2\xa5\x99\
-L\xb9\xa1\x16\xc5\xc7\xbb\xed\xff\x0a\xf2\xb2;M\x9f\xb5\
-\x908\x03\x16,\x9a\xcb\xf8\xe0\xde\x04\x96\xc7\x0f\xdby\
-\xe7MO\xc8\xfbv\xbf\xe5\xff\xb4\x0a\x9b\x9by\x851\
-\xdc\xd3g-\x82k\x983\x7f)\xe3l F1`\
-\xca\xf4y\x8c\xd7\xaeMg\x02i~\xf2\xa8Y\xe1\xd2\
-\xa5\xfa\xdc_\x9f7\xfd\xffx\xbf\xea\x7fE\x96m\x97\
-\x81\x81>'33\x8b\xa5\x9e8gi\xb8\x9e\xc0f\
-&&\xa6D\x14\x03&N\x9d\xc7x\xef\xdeD\x96'\
-\x0f[E\x9f>j\xd6\xbdu\xb3\x22\xef\xd7\xb7=\xff\
-\xbe\x7f\xe8\xfb\x7f~S\xcc\xef\x05\xc5\xea\x9fNOQ\
-\xfb\x7f\xbaM\xed\xbf\x87\x1a\xefn5-\x1dV\x14\x03\
-f\xcf[\xce\xa8\xa4\xa9![W\xed\x9b}\xefJ\xcb\
-\xcew\xaf&\x7f\xfa\xfee\xc9\xff\xef\x1f\xfa\xff\xbf\xbf\
-\x95\xf2\xff\xc9^\x83\xffW\x17\xaa\xfdot\x12{\xc4\
-\xc7\xc7/\x8e\x12\x06Y\xb9\x85\xcc\xb2\x82\x1c\xf3\xa7D\
-\xab\xfe\xfa\xbe%\xe2\xff\x8fgm\xff\x7f|\x9a\x08\xd6\
-\xfc\xf5Y\xcd\xff\xd7\xe7\xfc\xfe\xdf\xde\xa0\xf5\x7fE\x94\
-\xecO\x16\x16V\xebi3\xe7\xa3\x06\xe2\xe4is\x18\
-\xe7/Z\xc1\xc8\xce\xc1i\x10\xe5\xa8\xd2\xbe\xa6\xcd\xe7\
-\xf6\xc3m\x99\xff~^(\xf8\xff\xe1j\xe0\xff\x17G\
-L\xff\xdf\xdf\xae\xf6\xbf\xc2]\xf4\xba\x9a\x9a\x06\x1bF\
-,\x00\x01#2\xe6\xe6\xe6`Q\xd6\x941_\xde\xe4\
-q\xfb\xc3y\xd3\xff\x1b\x8aT\xff\xbf?`\xff\xff\xdc\
-l\xe5\xff\xea\xc2\x1c9\xd3g-\xc0i\x00\x13\x10\x8b\
-\x03\xb1?\x10\xe7\xf5\x16\xd8\xde\xf8p\xc6\xe4\xbf\x9d<\
-\xf7t\x7fC\xe9\x95\xb7\x96\xd9\xff\x9b\x9c,\xfdN@\
-@H\x14\x9b\x01LP,\x06\xc4\x19@|\x22;\xca\
-\xf0\xe7\xe9\xf9\x06\xff\x81\xec\x03@\xbc^\x82\x9f\xf3\xf6\
-\x9e\x1a\xf3_az\x823P\xd2\x01T#3\x10\x0b\
-\x00\xb1\x1e\x10\x17\x03\xf1\xd1\xa8@\xdd\x9f\xad\x09J \
-\x03\xfe\x00\xf17 >\x0f\xb4kf\xb9\xa7\xea\x0d}\
-i>#d\x03\xb4\x808\x08\x88k\x81x\x09\xd4\xc6\
-\x1b\x11a\x06\xdf\xec\x94\xb8\xdf\x03\xd9;\x81x\x1a\x10\
-\xf7\x82\xd4\xb0\xb2\xb1G\xf9\xda\x99:L\x9d9\x9f\x09\
-f\x80\x0e\x10;\x02\xb1\x13\x10[\x00\xb1\x01\x10\x07\x06\
-{h\x9c\x02\xd2k\xa0\x86\x8b\x001\x17\x10\xf3\x80\xb0\
-\x88\x88(\xcb,hFC\xf6\x02\x08\xb3\x001+\x10\
-K122\xe4\x01i7 \x96\x01b6\xa88\x0b\
-T=cW\xef$\xb0\x01\x00\xceo{\xf5UL\xf0\
-\xac\x00\x00\x00\x00IEND\xaeB`\x82\
+\x00\x00\x02e\
+<\
+svg xmlns=\x22http:\
+//www.w3.org/200\
+0/svg\x22 width=\x2224\
+\x22 height=\x2224\x22 fi\
+ll=\x22#0d0d0d\x22><pa\
+th d=\x22M8.41 18.1\
+38L12 15.845l3.5\
+9 2.323-.94-4.34\
+5 3.162-2.897-4.\
+159-.392L12 6.43\
+l-1.652 4.073-4.\
+159.392 3.162 2.\
+927-.94 4.315zm-\
+1.346 3.696a1.04\
+ 1.04 0 0 1-1.56\
+7-1.104l1.318-6.\
+033-4.476-4.11c-\
+.665-.611-.293-1\
+.726.604-1.808l5\
+.866-.539 2.229-\
+5.587c.348-.872 \
+1.575-.872 1.923\
+ 0l2.229 5.587 5\
+.866.539c.897.08\
+2 1.269 1.197.60\
+4 1.808l-4.476 4\
+.11 1.318 6.033a\
+1.04 1.04 0 0 1-\
+1.567 1.104L12 1\
+8.681l-4.935 3.1\
+53z\x22/><path d=\x22M\
+12 5l-1.796 5.52\
+8H4.392l4.702 3.\
+416-1.796 5.528L\
+12 16.056l4.702 \
+3.416-1.796-5.52\
+8 4.702-3.416h-5\
+.812L12 5z\x22/></s\
+vg>\x0a\
+\x00\x00\x01\xfa\
+<\
+svg xmlns=\x22http:\
+//www.w3.org/200\
+0/svg\x22 width=\x2224\
+\x22 height=\x2224\x22 fi\
+ll=\x22none\x22><path \
+d=\x22M8.41 18.138L\
+12 15.845l3.59 2\
+.323-.94-4.345 3\
+.162-2.897-4.159\
+-.392L12 6.43l-1\
+.652 4.073-4.159\
+.392 3.162 2.927\
+-.94 4.315zm-1.3\
+46 3.696a1.04 1.\
+04 0 0 1-1.567-1\
+.104l1.318-6.033\
+-4.476-4.11c-.66\
+5-.611-.293-1.72\
+6.604-1.808l5.86\
+6-.539 2.229-5.5\
+87c.348-.872 1.5\
+75-.872 1.923 0l\
+2.229 5.587 5.86\
+6.539c.897.082 1\
+.269 1.197.604 1\
+.808l-4.476 4.11\
+ 1.318 6.033a1.0\
+4 1.04 0 0 1-1.5\
+67 1.104L12 18.6\
+81l-4.935 3.153z\
+\x22 fill=\x22#0d0d0d\x22\
+/></svg>\x0a\
"
qt_resource_name = b"\
@@ -64,19 +88,25 @@ qt_resource_name = b"\
\x07\x03}\xc3\
\x00i\
\x00m\x00a\x00g\x00e\x00s\
+\x00\x0f\
+\x02\x11 \x07\
+\x00s\
+\x00t\x00a\x00r\x00-\x00f\x00i\x00l\x00l\x00e\x00d\x00.\x00s\x00v\x00g\
\x00\x08\
-\x0a\x85X\x07\
+\x0a\x85U\x87\
\x00s\
-\x00t\x00a\x00r\x00.\x00p\x00n\x00g\
+\x00t\x00a\x00r\x00.\x00s\x00v\x00g\
"
qt_resource_struct = b"\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
\x00\x00\x00\x00\x00\x00\x00\x00\
-\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\
+\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x02\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x12\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
-\x00\x00\x01j\x965\xd3\xea\
+\x00\x00\x01\x8c\xd4\xc79\xcf\
+\x00\x00\x006\x00\x00\x00\x00\x00\x01\x00\x00\x02i\
+\x00\x00\x01\x8c\xd4\xc79\xcf\
"
def qInitResources():
diff --git a/examples/sql/books/ui_bookwindow.py b/examples/sql/books/ui_bookwindow.py
index dc532744b..52795217e 100644
--- a/examples/sql/books/ui_bookwindow.py
+++ b/examples/sql/books/ui_bookwindow.py
@@ -3,21 +3,26 @@
################################################################################
## Form generated from reading UI file 'bookwindow.ui'
##
-## Created by: Qt User Interface Compiler version 5.14.0
+## Created by: Qt User Interface Compiler version 6.7.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
-from PySide2.QtCore import (QCoreApplication, QMetaObject, QObject, QPoint,
- QRect, QSize, QUrl, Qt)
-from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QFont,
- QFontDatabase, QIcon, QLinearGradient, QPalette, QPainter, QPixmap,
- QRadialGradient)
-from PySide2.QtWidgets import *
+from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
+ QMetaObject, QObject, QPoint, QRect,
+ QSize, QTime, QUrl, Qt)
+from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
+ QFont, QFontDatabase, QGradient, QIcon,
+ QImage, QKeySequence, QLinearGradient, QPainter,
+ QPalette, QPixmap, QRadialGradient, QTransform)
+from PySide6.QtWidgets import (QAbstractItemView, QApplication, QComboBox, QFormLayout,
+ QGroupBox, QHeaderView, QLabel, QLineEdit,
+ QMainWindow, QSizePolicy, QSpinBox, QTableView,
+ QVBoxLayout, QWidget)
class Ui_BookWindow(object):
def setupUi(self, BookWindow):
- if BookWindow.objectName():
+ if not BookWindow.objectName():
BookWindow.setObjectName(u"BookWindow")
BookWindow.resize(601, 420)
self.centralWidget = QWidget(BookWindow)
@@ -127,3 +132,4 @@ class Ui_BookWindow(object):
self.yearEdit.setPrefix("")
self.label.setText(QCoreApplication.translate("BookWindow", u"<b>Rating:</b>", None))
# retranslateUi
+
diff --git a/examples/sql/relationaltablemodel/connection.py b/examples/sql/relationaltablemodel/connection.py
new file mode 100644
index 000000000..6bfc828c8
--- /dev/null
+++ b/examples/sql/relationaltablemodel/connection.py
@@ -0,0 +1,18 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+"""PySide6 port of the relationaltablemodel example from Qt v6.x"""
+
+
+from PySide6.QtSql import QSqlDatabase
+
+
+def createConnection():
+
+ def check(func, *args):
+ if not func(*args):
+ raise ValueError(func.__self__.lastError())
+ db = QSqlDatabase.addDatabase("QSQLITE")
+ db.setDatabaseName(":memory:")
+
+ check(db.open)
diff --git a/examples/sql/relationaltablemodel/relationaltablemodel.py b/examples/sql/relationaltablemodel/relationaltablemodel.py
new file mode 100644
index 000000000..d2efac2dc
--- /dev/null
+++ b/examples/sql/relationaltablemodel/relationaltablemodel.py
@@ -0,0 +1,77 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+"""PySide6 port of the relationaltablemodel example from Qt v6.x"""
+
+import sys
+
+import connection
+
+from PySide6.QtCore import QObject, Qt
+from PySide6.QtSql import (QSqlQuery, QSqlRelation, QSqlRelationalDelegate,
+ QSqlRelationalTableModel)
+from PySide6.QtWidgets import QApplication, QTableView
+
+
+def initializeModel(model):
+
+ model.setTable("employee")
+ model.setEditStrategy(QSqlRelationalTableModel.OnManualSubmit)
+ model.setRelation(2, QSqlRelation("city", "id", "name"))
+ model.setRelation(3, QSqlRelation("country", "id", "name"))
+ model.setHeaderData(0, Qt.Horizontal, QObject().tr("ID"))
+
+ model.setHeaderData(1, Qt.Horizontal, QObject().tr("Name"))
+ model.setHeaderData(2, Qt.Horizontal, QObject().tr("City"))
+ model.setHeaderData(3, Qt.Horizontal, QObject().tr("Country"))
+
+ model.select()
+
+
+def createView(title, model):
+
+ table_view = QTableView()
+ table_view.setModel(model)
+ table_view.setItemDelegate(QSqlRelationalDelegate(table_view))
+ table_view.setWindowTitle(title)
+
+ return table_view
+
+
+def createRelationalTables():
+
+ query = QSqlQuery()
+
+ query.exec("create table employee(id int primary key, name varchar(20), city int, country int)")
+ query.exec("insert into employee values(1, 'Espen', 5000, 47)")
+ query.exec("insert into employee values(2, 'Harald', 80000, 49)")
+ query.exec("insert into employee values(3, 'Sam', 100, 1)")
+
+ query.exec("create table city(id int, name varchar(20))")
+ query.exec("insert into city values(100, 'San Jose')")
+ query.exec("insert into city values(5000, 'Oslo')")
+ query.exec("insert into city values(80000, 'Munich')")
+
+ query.exec("create table country(id int, name varchar(20))")
+ query.exec("insert into country values(1, 'USA')")
+ query.exec("insert into country values(47, 'Norway')")
+ query.exec("insert into country values(49, 'Germany')")
+
+
+if __name__ == "__main__":
+ app = QApplication(sys.argv)
+
+ connection.createConnection()
+ createRelationalTables()
+
+ model = QSqlRelationalTableModel()
+
+ initializeModel(model)
+
+ title = "Relational Table Model"
+
+ window = createView(title, model)
+ window.resize(600, 200)
+ window.show()
+
+ sys.exit(app.exec())