diff options
author | Friedemann Kleint <[email protected]> | 2024-12-17 16:49:50 +0100 |
---|---|---|
committer | Friedemann Kleint <[email protected]> | 2024-12-18 16:15:45 +0100 |
commit | 1f26c800e0dff519b89418aaed4395d5497486df (patch) | |
tree | 1e5d7df257da6e2746353290962873c400b2720a | |
parent | d27ad166e888c52e5ec77eb9db85bf7da2ed9ddc (diff) |
Widget examples: Use fully qualified enumerations
Pick-to: 6.8
Task-number: PYSIDE-1735
Change-Id: I99890e66ff29600072175185f471be0d7646c45b
Reviewed-by: Cristian Maureira-Fredes <[email protected]>
57 files changed, 622 insertions, 607 deletions
diff --git a/examples/widgets/animation/animatedtiles/animatedtiles.py b/examples/widgets/animation/animatedtiles/animatedtiles.py index b26ac024b..a014a2f45 100644 --- a/examples/widgets/animation/animatedtiles/animatedtiles.py +++ b/examples/widgets/animation/animatedtiles/animatedtiles.py @@ -26,7 +26,7 @@ class Pixmap(QObject): super().__init__() self.pixmap_item = QGraphicsPixmapItem(pix) - self.pixmap_item.setCacheMode(QGraphicsItem.DeviceCoordinateCache) + self.pixmap_item.setCacheMode(QGraphicsItem.CacheMode.DeviceCoordinateCache) def set_pos(self, pos): self.pixmap_item.setPos(pos) @@ -46,7 +46,7 @@ class Button(QGraphicsWidget): self._pix = pixmap self.setAcceptHoverEvents(True) - self.setCacheMode(QGraphicsItem.DeviceCoordinateCache) + self.setCacheMode(QGraphicsItem.CacheMode.DeviceCoordinateCache) def boundingRect(self): return QRectF(-65, -65, 130, 130) @@ -58,16 +58,16 @@ class Button(QGraphicsWidget): return path def paint(self, painter, option, widget): - down = option.state & QStyle.State_Sunken + down = option.state & QStyle.StateFlag.State_Sunken r = self.boundingRect() grad = QLinearGradient(r.topLeft(), r.bottomRight()) - if option.state & QStyle.State_MouseOver: - color_0 = Qt.white + if option.state & QStyle.StateFlag.State_MouseOver: + color_0 = Qt.GlobalColor.white else: - color_0 = Qt.lightGray + color_0 = Qt.GlobalColor.lightGray - color_1 = Qt.darkGray + color_1 = Qt.GlobalColor.darkGray if down: color_0, color_1 = color_1, color_0 @@ -75,12 +75,12 @@ class Button(QGraphicsWidget): grad.setColorAt(0, color_0) grad.setColorAt(1, color_1) - painter.setPen(Qt.darkGray) + painter.setPen(Qt.GlobalColor.darkGray) painter.setBrush(grad) painter.drawEllipse(r) - color_0 = Qt.darkGray - color_1 = Qt.lightGray + color_0 = Qt.GlobalColor.darkGray + color_1 = Qt.GlobalColor.lightGray if down: color_0, color_1 = color_1, color_0 @@ -88,7 +88,7 @@ class Button(QGraphicsWidget): grad.setColorAt(0, color_0) grad.setColorAt(1, color_1) - painter.setPen(Qt.NoPen) + painter.setPen(Qt.PenStyle.NoPen) painter.setBrush(grad) if down: @@ -109,7 +109,7 @@ class Button(QGraphicsWidget): class View(QGraphicsView): def resizeEvent(self, event): super(View, self).resizeEvent(event) - self.fitInView(self.sceneRect(), Qt.KeepAspectRatio) + self.fitInView(self.sceneRect(), Qt.AspectRatioMode.KeepAspectRatio) if __name__ == '__main__': @@ -188,10 +188,11 @@ if __name__ == '__main__': # Ui. view = View(scene) view.setWindowTitle("Animated Tiles") - view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate) + view.setViewportUpdateMode(QGraphicsView.ViewportUpdateMode.BoundingRectViewportUpdate) view.setBackgroundBrush(QBrush(bg_pix)) - view.setCacheMode(QGraphicsView.CacheBackground) - view.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.SmoothPixmapTransform) + view.setCacheMode(QGraphicsView.CacheModeFlag.CacheBackground) + view.setRenderHints(QPainter.RenderHint.Antialiasing + | QPainter.RenderHint.SmoothPixmapTransform) view.show() states = QStateMachine() @@ -203,7 +204,7 @@ if __name__ == '__main__': for i, item in enumerate(items): anim = QPropertyAnimation(item, b'pos') anim.setDuration(750 + i * 25) - anim.setEasingCurve(QEasingCurve.InOutBack) + anim.setEasingCurve(QEasingCurve.Type.InOutBack) group.addAnimation(anim) trans = root_state.addTransition(ellipse_button.pressed, ellipse_state) diff --git a/examples/widgets/animation/appchooser/appchooser.py b/examples/widgets/animation/appchooser/appchooser.py index 6b29f9997..8386909fe 100644 --- a/examples/widgets/animation/appchooser/appchooser.py +++ b/examples/widgets/animation/appchooser/appchooser.py @@ -66,7 +66,7 @@ if __name__ == '__main__': p4.setGeometry(QRectF(0.0, 236.0, 64.0, 64.0)) scene = QGraphicsScene(0, 0, 300, 300) - scene.setBackgroundBrush(Qt.white) + scene.setBackgroundBrush(Qt.GlobalColor.white) scene.addItem(p1) scene.addItem(p2) scene.addItem(p3) @@ -74,12 +74,12 @@ if __name__ == '__main__': window = QGraphicsView(scene) window.setFrameStyle(0) - window.setAlignment(Qt.AlignLeft | Qt.AlignTop) - window.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - window.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + window.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop) + window.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) + window.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) machine = QStateMachine() - machine.setGlobalRestorePolicy(QStateMachine.RestoreProperties) + machine.setGlobalRestorePolicy(QStateMachine.RestorePolicy.RestoreProperties) group = QState(machine) selected_rect = QRect(86, 86, 128, 128) diff --git a/examples/widgets/desktop/screenshot/screenshot.py b/examples/widgets/desktop/screenshot/screenshot.py index 4494ecab4..fba1f71b0 100644 --- a/examples/widgets/desktop/screenshot/screenshot.py +++ b/examples/widgets/desktop/screenshot/screenshot.py @@ -21,8 +21,9 @@ class Screenshot(QWidget): self.screenshot_label = QLabel(self) - self.screenshot_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) - self.screenshot_label.setAlignment(Qt.AlignCenter) + self.screenshot_label.setSizePolicy(QSizePolicy.Policy.Expanding, + QSizePolicy.Policy.Expanding) + self.screenshot_label.setAlignment(Qt.AlignmentFlag.AlignCenter) screen_geometry: QRect = self.screen().geometry() self.screenshot_label.setMinimumSize( @@ -56,7 +57,7 @@ class Screenshot(QWidget): save_screenshot_button.clicked.connect(self.save_screenshot) buttons_layout.addWidget(save_screenshot_button) quit_screenshot_button = QPushButton("Quit", self) - quit_screenshot_button.setShortcut(Qt.CTRL | Qt.Key_Q) + quit_screenshot_button.setShortcut(Qt.Modifier.CTRL | Qt.Key.Key_Q) quit_screenshot_button.clicked.connect(self.close) buttons_layout.addWidget(quit_screenshot_button) buttons_layout.addStretch() @@ -70,7 +71,7 @@ class Screenshot(QWidget): def resizeEvent(self, event): scaled_size = self.original_pixmap.size() - scaled_size.scale(self.screenshot_label.size(), Qt.KeepAspectRatio) + scaled_size.scale(self.screenshot_label.size(), Qt.AspectRatioMode.KeepAspectRatio) if scaled_size != self.screenshot_label.pixmap().size(): self.update_screenshot_label() @@ -85,14 +86,14 @@ class Screenshot(QWidget): @Slot() def save_screenshot(self): fmt = "png" # In order to avoid shadowing built-in format - initial_path = QStandardPaths.writableLocation(QStandardPaths.PicturesLocation) + initial_path = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.PicturesLocation) # noqa: E501 if not initial_path: initial_path = QDir.currentPath() initial_path += f"/untitled.{fmt}" fileDialog = QFileDialog(self, "Save As", initial_path) - fileDialog.setAcceptMode(QFileDialog.AcceptSave) - fileDialog.setFileMode(QFileDialog.AnyFile) + fileDialog.setAcceptMode(QFileDialog.AcceptMode.AcceptSave) + fileDialog.setFileMode(QFileDialog.FileMode.AnyFile) fileDialog.setDirectory(initial_path) mime_types = [] @@ -101,7 +102,7 @@ class Screenshot(QWidget): fileDialog.setMimeTypeFilters(mime_types) fileDialog.selectMimeTypeFilter("image/" + fmt) fileDialog.setDefaultSuffix(fmt) - if fileDialog.exec() != QDialog.Accepted: + if fileDialog.exec() != QDialog.DialogCode.Accepted: return file_name = fileDialog.selectedFiles()[0] @@ -143,8 +144,8 @@ class Screenshot(QWidget): self.screenshot_label.setPixmap( self.original_pixmap.scaled( self.screenshot_label.size(), - Qt.KeepAspectRatio, - Qt.SmoothTransformation, + Qt.AspectRatioMode.KeepAspectRatio, + Qt.TransformationMode.SmoothTransformation, ) ) diff --git a/examples/widgets/dialogs/classwizard/classwizard.py b/examples/widgets/dialogs/classwizard/classwizard.py index d956ec7c5..d7014313f 100644 --- a/examples/widgets/dialogs/classwizard/classwizard.py +++ b/examples/widgets/dialogs/classwizard/classwizard.py @@ -65,9 +65,9 @@ class ClassWizard(QWizard): self._output_index = self.addPage(OutputFilesPage()) self.addPage(ConclusionPage()) - self.setPixmap(QWizard.BannerPixmap, + self.setPixmap(QWizard.WizardPixmap.BannerPixmap, QPixmap(':/images/banner.png')) - self.setPixmap(QWizard.BackgroundPixmap, + self.setPixmap(QWizard.WizardPixmap.BackgroundPixmap, QPixmap(':/images/background.png')) self.setWindowTitle("Class Wizard") @@ -218,7 +218,7 @@ class IntroPage(QWizardPage): super().__init__(parent) self.setTitle("Introduction") - self.setPixmap(QWizard.WatermarkPixmap, + self.setPixmap(QWizard.WizardPixmap.WatermarkPixmap, QPixmap(':/images/watermark1.png')) label = QLabel(INTRODUCTION) @@ -235,7 +235,7 @@ class ClassInfoPage(QWizardPage): self.setTitle("Class Information") self.setSubTitle("Specify basic information about the class for " "which you want to generate a skeleton source code file.") - self.setPixmap(QWizard.LogoPixmap, + self.setPixmap(QWizard.WizardPixmap.LogoPixmap, QPixmap(':/qt-project.org/logos/pysidelogo.png')) class_name_line_edit = QLineEdit() @@ -278,7 +278,7 @@ class QObjectPage(QWizardPage): self.setTitle("QObject parameters") self.setSubTitle("Specify the signals, slots and properties.") - self.setPixmap(QWizard.LogoPixmap, + self.setPixmap(QWizard.WizardPixmap.LogoPixmap, QPixmap(':/qt-project.org/logos/pysidelogo.png')) layout = QVBoxLayout(self) self._properties_chooser = PropertyChooser() @@ -296,7 +296,7 @@ class OutputFilesPage(QWizardPage): self.setTitle("Output Files") self.setSubTitle("Specify where you want the wizard to put the " "generated skeleton code.") - self.setPixmap(QWizard.LogoPixmap, + self.setPixmap(QWizard.WizardPixmap.LogoPixmap, QPixmap(':/qt-project.org/logos/pysidelogo.png')) output_dir_label = QLabel("&Output directory:") @@ -354,7 +354,7 @@ class ConclusionPage(QWizardPage): super().__init__(parent) self.setTitle("Conclusion") - self.setPixmap(QWizard.WatermarkPixmap, + self.setPixmap(QWizard.WizardPixmap.WatermarkPixmap, QPixmap(':/images/watermark1.png')) self.label = QLabel() @@ -368,7 +368,7 @@ class ConclusionPage(QWizardPage): layout.addWidget(self._launch_check_box) def initializePage(self): - finish_text = self.wizard().buttonText(QWizard.FinishButton) + finish_text = self.wizard().buttonText(QWizard.WizardButton.FinishButton) finish_text = finish_text.replace('&', '') self.label.setText(f"Click {finish_text} to generate the class skeleton.") self._launch_check_box.setChecked(True) diff --git a/examples/widgets/dialogs/classwizard/listchooser.py b/examples/widgets/dialogs/classwizard/listchooser.py index eb621baca..f7239ae3c 100644 --- a/examples/widgets/dialogs/classwizard/listchooser.py +++ b/examples/widgets/dialogs/classwizard/listchooser.py @@ -34,7 +34,8 @@ class ValidatingInputDialog(QDialog): self._form_layout.addRow(label, self._lineedit) layout.addLayout(self._form_layout) - bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok + | QDialogButtonBox.StandardButton.Cancel) layout.addWidget(bb) bb.rejected.connect(self.reject) bb.accepted.connect(self.accept) diff --git a/examples/widgets/dialogs/standarddialogs/standarddialogs.py b/examples/widgets/dialogs/standarddialogs/standarddialogs.py index 04f5fc838..7bd68620a 100644 --- a/examples/widgets/dialogs/standarddialogs/standarddialogs.py +++ b/examples/widgets/dialogs/standarddialogs/standarddialogs.py @@ -49,7 +49,7 @@ class Dialog(QDialog): self._error_message_dialog = QErrorMessage(self) - frame_style = QFrame.Sunken | QFrame.Panel + frame_style = QFrame.Shadow.Sunken | QFrame.Shape.Panel self._integer_label = QLabel() self._integer_label.setFrameStyle(frame_style) @@ -76,25 +76,25 @@ class Dialog(QDialog): self._color_button = QPushButton("QColorDialog.get&Color()") self._color_options = DialogOptionsWidget(QColorDialog.ColorDialogOption(0)) self._color_options.add_checkbox("Show alpha channel", - QColorDialog.ShowAlphaChannel) + QColorDialog.ColorDialogOption.ShowAlphaChannel) self._color_options.add_checkbox("No buttons", - QColorDialog.NoButtons) + QColorDialog.ColorDialogOption.NoButtons) self._font_label = QLabel() self._font_label.setFrameStyle(frame_style) self._font_button = QPushButton("QFontDialog.get&Font()") self._font_options = DialogOptionsWidget(QFontDialog.FontDialogOption(0)) self._font_options.add_checkbox("Do not use native dialog", - QFontDialog.DontUseNativeDialog) + QFontDialog.FontDialogOption.DontUseNativeDialog) self._font_options.add_checkbox("Show scalable fonts", - QFontDialog.ScalableFonts) + QFontDialog.FontDialogOption.ScalableFonts) self._font_options.add_checkbox("Show non-scalable fonts", - QFontDialog.NonScalableFonts) + QFontDialog.FontDialogOption.NonScalableFonts) self._font_options.add_checkbox("Show monospaced fonts", - QFontDialog.MonospacedFonts) + QFontDialog.FontDialogOption.MonospacedFonts) self._font_options.add_checkbox("Show proportional fonts", - QFontDialog.ProportionalFonts) - self._font_options.add_checkbox("No buttons", QFontDialog.NoButtons) + QFontDialog.FontDialogOption.ProportionalFonts) + self._font_options.add_checkbox("No buttons", QFontDialog.FontDialogOption.NoButtons) self._directory_label = QLabel() self._directory_label.setFrameStyle(frame_style) @@ -114,18 +114,18 @@ class Dialog(QDialog): self._file_options = DialogOptionsWidget(QFileDialog.Option(0)) self._file_options.add_checkbox("Do not use native dialog", - QFileDialog.DontUseNativeDialog) + QFileDialog.Option.DontUseNativeDialog) self._file_options.add_checkbox("Show directories only", - QFileDialog.ShowDirsOnly) + QFileDialog.Option.ShowDirsOnly) self._file_options.add_checkbox("Do not resolve symlinks", - QFileDialog.DontResolveSymlinks) + QFileDialog.Option.DontResolveSymlinks) self._file_options.add_checkbox("Do not confirm overwrite", - QFileDialog.DontConfirmOverwrite) - self._file_options.add_checkbox("Readonly", QFileDialog.ReadOnly) + QFileDialog.Option.DontConfirmOverwrite) + self._file_options.add_checkbox("Readonly", QFileDialog.Option.ReadOnly) self._file_options.add_checkbox("Hide name filter details", - QFileDialog.HideNameFilterDetails) + QFileDialog.Option.HideNameFilterDetails) self._file_options.add_checkbox("Do not use custom directory icons (Windows)", - QFileDialog.DontUseCustomDirectoryIcons) + QFileDialog.Option.DontUseCustomDirectoryIcons) self._critical_label = QLabel() self._critical_label.setFrameStyle(frame_style) @@ -179,7 +179,7 @@ class Dialog(QDialog): layout.addWidget(self._text_label, 3, 1) layout.addWidget(self._multiline_text_label, 4, 1) layout.addWidget(self._multiline_text_button, 4, 0) - spacer = QSpacerItem(0, 0, QSizePolicy.Ignored, QSizePolicy.MinimumExpanding) + spacer = QSpacerItem(0, 0, QSizePolicy.Policy.Ignored, QSizePolicy.Policy.MinimumExpanding) layout.addItem(spacer, 5, 0) toolbox.addItem(page, "Input Dialogs") @@ -187,7 +187,7 @@ class Dialog(QDialog): layout = QGridLayout(page) layout.addWidget(self._color_button, 0, 0) layout.addWidget(self._color_label, 0, 1) - spacer = QSpacerItem(0, 0, QSizePolicy.Ignored, QSizePolicy.MinimumExpanding) + spacer = QSpacerItem(0, 0, QSizePolicy.Policy.Ignored, QSizePolicy.Policy.MinimumExpanding) layout.addItem(spacer, 1, 0) layout.addWidget(self._color_options, 2, 0, 1, 2) toolbox.addItem(page, "Color Dialog") @@ -196,7 +196,7 @@ class Dialog(QDialog): layout = QGridLayout(page) layout.addWidget(self._font_button, 0, 0) layout.addWidget(self._font_label, 0, 1) - spacer = QSpacerItem(0, 0, QSizePolicy.Ignored, QSizePolicy.MinimumExpanding) + spacer = QSpacerItem(0, 0, QSizePolicy.Policy.Ignored, QSizePolicy.Policy.MinimumExpanding) layout.addItem(spacer, 1, 0) layout.addWidget(self._font_options, 2, 0, 1, 2) toolbox.addItem(page, "Font Dialog") @@ -211,7 +211,7 @@ class Dialog(QDialog): layout.addWidget(self._open_file_names_label, 2, 1) layout.addWidget(self._save_file_name_button, 3, 0) layout.addWidget(self._save_file_name_label, 3, 1) - spacer = QSpacerItem(0, 0, QSizePolicy.Ignored, QSizePolicy.MinimumExpanding) + spacer = QSpacerItem(0, 0, QSizePolicy.Policy.Ignored, QSizePolicy.Policy.MinimumExpanding) layout.addItem(spacer, 4, 0) layout.addWidget(self._file_options, 5, 0, 1, 2) @@ -228,7 +228,7 @@ class Dialog(QDialog): layout.addWidget(self._warning_button, 3, 0) layout.addWidget(self._warning_label, 3, 1) layout.addWidget(self._error_button, 4, 0) - spacer = QSpacerItem(0, 0, QSizePolicy.Ignored, QSizePolicy.MinimumExpanding) + spacer = QSpacerItem(0, 0, QSizePolicy.Policy.Ignored, QSizePolicy.Policy.MinimumExpanding) layout.addItem(spacer, 5, 0) toolbox.addItem(page, "Message Boxes") @@ -273,8 +273,8 @@ class Dialog(QDialog): @Slot() def set_color(self): options_value = self._color_options.value() - options = QColorDialog.ColorDialogOptions(options_value) - color = QColorDialog.getColor(Qt.green, self, "Select Color", options) + options = QColorDialog.ColorDialogOption(options_value) + color = QColorDialog.getColor(Qt.GlobalColor.green, self, "Select Color", options) if color.isValid(): self._color_label.setText(color.name()) @@ -347,15 +347,15 @@ class Dialog(QDialog): Activating the liquid oxygen stirring fans caused an explosion in one of the tanks. Liquid oxygen levels are getting low. This may jeopardize the moon landing mission.""") - msg_box = QMessageBox(QMessageBox.Critical, "QMessageBox.critical()", + msg_box = QMessageBox(QMessageBox.Icon.Critical, "QMessageBox.critical()", "Houston, we have a problem", - QMessageBox.Abort | QMessageBox.Retry | QMessageBox.Ignore, - self) + QMessageBox.StandardButton.Abort | QMessageBox.StandardButton.Retry + | QMessageBox.StandardButton.Ignore, self) msg_box.setInformativeText(m) reply = msg_box.exec() - if reply == QMessageBox.Abort: + if reply == QMessageBox.StandardButton.Abort: self._critical_label.setText("Abort") - elif reply == QMessageBox.Retry: + elif reply == QMessageBox.StandardButton.Retry: self._critical_label.setText("Retry") else: self._critical_label.setText("Ignore") @@ -367,12 +367,12 @@ class Dialog(QDialog): the conclusion of Elvis Presley concerts in order to disperse audiences who lingered in hopes of an encore. It has since become a catchphrase and punchline.""") - msg_box = QMessageBox(QMessageBox.Information, "QMessageBox.information()", + msg_box = QMessageBox(QMessageBox.Icon.Information, "QMessageBox.information()", "Elvis has left the building.", - QMessageBox.Ok, self) + QMessageBox.StandardButton.Ok, self) msg_box.setInformativeText(m) reply = msg_box.exec() - if reply == QMessageBox.Ok: + if reply == QMessageBox.StandardButton.Ok: self._information_label.setText("OK") else: self._information_label.setText("Escape") @@ -385,29 +385,30 @@ class Dialog(QDialog): meat patty. The cheese is usually added to the cooking hamburger patty shortly before serving, which allows the cheese to melt.""") - msg_box = QMessageBox(QMessageBox.Question, "QMessageBox.question()", + msg_box = QMessageBox(QMessageBox.Icon.Question, "QMessageBox.question()", "Would you like cheese with that?", - QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel) + QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No + | QMessageBox.StandardButton.Cancel) msg_box.setInformativeText(m) reply = msg_box.exec() - if reply == QMessageBox.Yes: + if reply == QMessageBox.StandardButton.Yes: self._question_label.setText("Yes") - elif reply == QMessageBox.No: + elif reply == QMessageBox.StandardButton.No: self._question_label.setText("No") else: self._question_label.setText("Cancel") @Slot() def warning_message(self): - msg_box = QMessageBox(QMessageBox.Warning, "QMessageBox.warning()", + msg_box = QMessageBox(QMessageBox.Icon.Warning, "QMessageBox.warning()", "Delete the only copy of your movie manuscript?", - QMessageBox.NoButton, self) + QMessageBox.StandardButton.NoButton, self) m = "You've been working on this manuscript for 738 days now. Hang in there!" msg_box.setInformativeText(m) msg_box.setDetailedText('"A long time ago in a galaxy far, far away...."') - msg_box.addButton("&Keep", QMessageBox.AcceptRole) - msg_box.addButton("Delete", QMessageBox.RejectRole) - if msg_box.exec() == QMessageBox.AcceptRole: + msg_box.addButton("&Keep", QMessageBox.ButtonRole.AcceptRole) + msg_box.addButton("Delete", QMessageBox.ButtonRole.RejectRole) + if msg_box.exec() == QMessageBox.ButtonRole.AcceptRole: self._warning_label.setText("Keep") else: self._warning_label.setText("Delete") diff --git a/examples/widgets/dialogs/tabdialog/tabdialog.py b/examples/widgets/dialogs/tabdialog/tabdialog.py index 0e6c5071b..c8eeec6b1 100644 --- a/examples/widgets/dialogs/tabdialog/tabdialog.py +++ b/examples/widgets/dialogs/tabdialog/tabdialog.py @@ -35,7 +35,7 @@ class TabDialog(QDialog): tab_widget.addTab(ApplicationsTab(file_info, self), "Applications") button_box = QDialogButtonBox( - QDialogButtonBox.Ok | QDialogButtonBox.Cancel + QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel ) button_box.accepted.connect(self.accept) @@ -57,20 +57,20 @@ class GeneralTab(QWidget): path_label = QLabel("Path:") path_value_label = QLabel(file_info.absoluteFilePath()) - path_value_label.setFrameStyle(QFrame.Panel | QFrame.Sunken) + path_value_label.setFrameStyle(QFrame.Shape.Panel | QFrame.Shadow.Sunken) size_label = QLabel("Size:") size = file_info.size() / 1024 size_value_label = QLabel(f"{size} K") - size_value_label.setFrameStyle(QFrame.Panel | QFrame.Sunken) + size_value_label.setFrameStyle(QFrame.Shape.Panel | QFrame.Shadow.Sunken) last_read_label = QLabel("Last Read:") last_read_value_label = QLabel(file_info.lastRead().toString()) - last_read_value_label.setFrameStyle(QFrame.Panel | QFrame.Sunken) + last_read_value_label.setFrameStyle(QFrame.Shape.Panel | QFrame.Shadow.Sunken) last_mod_label = QLabel("Last Modified:") last_mod_value_label = QLabel(file_info.lastModified().toString()) - last_mod_value_label.setFrameStyle(QFrame.Panel | QFrame.Sunken) + last_mod_value_label.setFrameStyle(QFrame.Shape.Panel | QFrame.Shadow.Sunken) main_layout = QVBoxLayout() main_layout.addWidget(file_name_label) @@ -109,11 +109,11 @@ class PermissionsTab(QWidget): owner_label = QLabel("Owner") owner_value_label = QLabel(file_info.owner()) - owner_value_label.setFrameStyle(QFrame.Panel | QFrame.Sunken) + owner_value_label.setFrameStyle(QFrame.Shape.Panel | QFrame.Shadow.Sunken) group_label = QLabel("Group") group_value_label = QLabel(file_info.group()) - group_value_label.setFrameStyle(QFrame.Panel | QFrame.Sunken) + group_value_label.setFrameStyle(QFrame.Shape.Panel | QFrame.Shadow.Sunken) permissions_layout = QVBoxLayout() permissions_layout.addWidget(readable) diff --git a/examples/widgets/draganddrop/draggableicons/draggableicons.py b/examples/widgets/draganddrop/draggableicons/draggableicons.py index d54528c6e..bbaa514a2 100644 --- a/examples/widgets/draganddrop/draggableicons/draggableicons.py +++ b/examples/widgets/draganddrop/draggableicons/draggableicons.py @@ -14,7 +14,7 @@ class DragWidget(QFrame): def __init__(self, parent: QWidget): super().__init__(parent) self.setMinimumSize(200, 200) - self.setFrameStyle(QFrame.Sunken | QFrame.StyledPanel) + self.setFrameStyle(QFrame.Shadow.Sunken | QFrame.Shape.StyledPanel) self.setAcceptDrops(True) path = Path(__file__).resolve().parent @@ -23,24 +23,24 @@ class DragWidget(QFrame): boat_icon.setPixmap(QPixmap(path / "images" / "boat.png")) boat_icon.move(10, 10) boat_icon.show() - boat_icon.setAttribute(Qt.WA_DeleteOnClose) + boat_icon.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose) car_icon = QLabel(self) car_icon.setPixmap(QPixmap(path / "images" / "car.png")) car_icon.move(100, 10) car_icon.show() - car_icon.setAttribute(Qt.WA_DeleteOnClose) + car_icon.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose) house_icon = QLabel(self) house_icon.setPixmap(QPixmap(path / "images" / "house.png")) house_icon.move(10, 80) house_icon.show() - house_icon.setAttribute(Qt.WA_DeleteOnClose) + house_icon.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose) def dragEnterEvent(self, event): if event.mimeData().hasFormat("application/x-dnditem_data"): if event.source() == self: - event.setDropAction(Qt.MoveAction) + event.setDropAction(Qt.DropAction.MoveAction) event.accept() else: event.acceptProposedAction() @@ -50,7 +50,7 @@ class DragWidget(QFrame): def dragMoveEvent(self, event): if event.mimeData().hasFormat("application/x-dnditem_data"): if event.source() == self: - event.setDropAction(Qt.MoveAction) + event.setDropAction(Qt.DropAction.MoveAction) event.accept() else: event.acceptProposedAction() @@ -60,7 +60,7 @@ class DragWidget(QFrame): def dropEvent(self, event): if event.mimeData().hasFormat("application/x-dnditem_data"): item_data: QByteArray = event.mimeData().data("application/x-dnditem_data") - data_stream = QDataStream(item_data, QIODevice.ReadOnly) + data_stream = QDataStream(item_data, QIODevice.OpenModeFlag.ReadOnly) pixmap = QPixmap() offset = QPoint() @@ -71,10 +71,10 @@ class DragWidget(QFrame): new_icon.setPixmap(pixmap) new_icon.move(event.position().toPoint() - offset) new_icon.show() - new_icon.setAttribute(Qt.WA_DeleteOnClose) + new_icon.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose) if event.source() == self: - event.setDropAction(Qt.MoveAction) + event.setDropAction(Qt.DropAction.MoveAction) event.accept() else: event.acceptProposedAction() @@ -89,7 +89,7 @@ class DragWidget(QFrame): pixmap = child.pixmap() item_data = QByteArray() - data_stream = QDataStream(item_data, QIODevice.WriteOnly) + data_stream = QDataStream(item_data, QIODevice.OpenModeFlag.WriteOnly) data_stream << pixmap << QPoint(event.position().toPoint() - child.pos()) @@ -108,7 +108,8 @@ class DragWidget(QFrame): child.setPixmap(temp_pixmap) - if drag.exec(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) == Qt.MoveAction: + if drag.exec(Qt.DropAction.CopyAction | Qt.DropAction.MoveAction, + Qt.DropAction.CopyAction) == Qt.DropAction.MoveAction: child.close() else: child.show() diff --git a/examples/widgets/draganddrop/draggabletext/draggabletext.py b/examples/widgets/draganddrop/draggabletext/draggabletext.py index 532e705c6..504e6bd02 100644 --- a/examples/widgets/draganddrop/draggabletext/draggabletext.py +++ b/examples/widgets/draganddrop/draggabletext/draggabletext.py @@ -18,8 +18,8 @@ class DragLabel(QLabel): super().__init__(text, parent) self.setAutoFillBackground(True) - self.setFrameShape(QFrame.Panel) - self.setFrameShadow(QFrame.Raised) + self.setFrameShape(QFrame.Shape.Panel) + self.setFrameShadow(QFrame.Shadow.Raised) def mousePressEvent(self, event): hot_spot = event.position().toPoint() @@ -38,9 +38,10 @@ class DragLabel(QLabel): drag.setPixmap(pixmap) drag.setHotSpot(hot_spot) - drop_action = drag.exec(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) + drop_action = drag.exec(Qt.DropAction.CopyAction | Qt.DropAction.MoveAction, + Qt.DropAction.CopyAction) - if drop_action == Qt.MoveAction: + if drop_action == Qt.DropAction.MoveAction: self.close() self.update() @@ -50,7 +51,7 @@ class DragWidget(QWidget): super().__init__(parent) dictionary_file = QFile(':/dictionary/words.txt') - dictionary_file.open(QIODevice.ReadOnly) + dictionary_file.open(QIODevice.OpenModeFlag.ReadOnly) x = 5 y = 5 @@ -65,7 +66,7 @@ class DragWidget(QWidget): y += word_label.height() + 2 new_palette = self.palette() - new_palette.setColor(QPalette.Window, Qt.white) + new_palette.setColor(QPalette.ColorRole.Window, Qt.GlobalColor.white) self.setPalette(new_palette) self.setAcceptDrops(True) @@ -75,7 +76,7 @@ class DragWidget(QWidget): def dragEnterEvent(self, event): if event.mimeData().hasText(): if event.source() in self.children(): - event.setDropAction(Qt.MoveAction) + event.setDropAction(Qt.DropAction.MoveAction) event.accept() else: event.acceptProposedAction() @@ -102,7 +103,7 @@ class DragWidget(QWidget): position += QPoint(new_label.width(), 0) if event.source() in self.children(): - event.setDropAction(Qt.MoveAction) + event.setDropAction(Qt.DropAction.MoveAction) event.accept() else: event.acceptProposedAction() diff --git a/examples/widgets/draganddrop/dropsite/droparea.py b/examples/widgets/draganddrop/dropsite/droparea.py index 86714b5d0..1c10a6867 100644 --- a/examples/widgets/draganddrop/dropsite/droparea.py +++ b/examples/widgets/draganddrop/dropsite/droparea.py @@ -14,15 +14,15 @@ class DropArea(QLabel): def __init__(self, parent=None): super().__init__(parent) self.setMinimumSize(200, 200) - self.setFrameStyle(QFrame.Sunken | QFrame.StyledPanel) - self.setAlignment(Qt.AlignCenter) + self.setFrameStyle(QFrame.Shadow.Sunken | QFrame.Shape.StyledPanel) + self.setAlignment(Qt.AlignmentFlag.AlignCenter) self.setAcceptDrops(True) self.setAutoFillBackground(True) self.clear() def dragEnterEvent(self, event): self.setText("<drop content>") - self.setBackgroundRole(QPalette.Highlight) + self.setBackgroundRole(QPalette.ColorRole.Highlight) event.acceptProposedAction() self.changed.emit(event.mimeData()) @@ -37,13 +37,13 @@ class DropArea(QLabel): self.setPixmap(QPixmap(mime_data.imageData())) elif mime_data.hasFormat("text/markdown"): self.setText(mime_data.data("text/markdown")) - self.setTextFormat(Qt.MarkdownText) + self.setTextFormat(Qt.TextFormat.MarkdownText) elif mime_data.hasHtml(): self.setText(mime_data.html()) - self.setTextFormat(Qt.RichText) + self.setTextFormat(Qt.TextFormat.RichText) elif mime_data.hasText(): self.setText(mime_data.text()) - self.setTextFormat(Qt.PlainText) + self.setTextFormat(Qt.TextFormat.PlainText) elif mime_data.hasUrls(): url_list = mime_data.urls() text = "" @@ -53,7 +53,7 @@ class DropArea(QLabel): else: self.setText("Cannot display data") - self.setBackgroundRole(QPalette.Dark) + self.setBackgroundRole(QPalette.ColorRole.Dark) event.acceptProposedAction() def dragLeaveEvent(self, event): @@ -63,6 +63,6 @@ class DropArea(QLabel): @Slot() def clear(self): self.setText("<drop content>") - self.setBackgroundRole(QPalette.Dark) + self.setBackgroundRole(QPalette.ColorRole.Dark) self.changed.emit(None) diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.py b/examples/widgets/draganddrop/dropsite/dropsitewindow.py index 5d09d87ae..0d6bbebf3 100644 --- a/examples/widgets/draganddrop/dropsite/dropsitewindow.py +++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.py @@ -41,7 +41,7 @@ class DropSiteWindow(QWidget): self._formats_table = QTableWidget() self._formats_table.setColumnCount(2) - self._formats_table.setEditTriggers(QAbstractItemView.NoEditTriggers) + self._formats_table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers) self._formats_table.setHorizontalHeaderLabels(["Format", "Content"]) self._formats_table.horizontalHeader().setStretchLastSection(True) @@ -50,11 +50,11 @@ class DropSiteWindow(QWidget): quit_button = QPushButton("Quit") button_box = QDialogButtonBox() - button_box.addButton(clear_button, QDialogButtonBox.ActionRole) - button_box.addButton(self._copy_button, QDialogButtonBox.ActionRole) + button_box.addButton(clear_button, QDialogButtonBox.ButtonRole.ActionRole) + button_box.addButton(self._copy_button, QDialogButtonBox.ButtonRole.ActionRole) self._copy_button.setVisible(False) - button_box.addButton(quit_button, QDialogButtonBox.RejectRole) + button_box.addButton(quit_button, QDialogButtonBox.ButtonRole.RejectRole) quit_button.clicked.connect(self.close) clear_button.clicked.connect(drop_area.clear) @@ -78,8 +78,8 @@ class DropSiteWindow(QWidget): for format in mime_data.formats(): format_item = QTableWidgetItem(format) - format_item.setFlags(Qt.ItemIsEnabled) - format_item.setTextAlignment(Qt.AlignTop | Qt.AlignLeft) + format_item.setFlags(Qt.ItemFlag.ItemIsEnabled) + format_item.setTextAlignment(Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft) if format == "text/plain": text = simplify_whitespace(mime_data.text()) diff --git a/examples/widgets/effects/lighting/lighting.py b/examples/widgets/effects/lighting/lighting.py index 4d98b8148..2970d55a2 100644 --- a/examples/widgets/effects/lighting/lighting.py +++ b/examples/widgets/effects/lighting/lighting.py @@ -33,7 +33,7 @@ class Lighting(QGraphicsView): timer.start() self.setRenderHint(QPainter.RenderHint.Antialiasing) - self.setFrameStyle(QFrame.NoFrame) + self.setFrameStyle(QFrame.Shape.NoFrame) def setup_scene(self): self.m_scene.setSceneRect(-300, -200, 600, 460) @@ -44,15 +44,15 @@ class Lighting(QGraphicsView): self.setBackgroundBrush(linear_grad) radial_grad = QRadialGradient(30, 30, 30) - radial_grad.setColorAt(0, Qt.yellow) - radial_grad.setColorAt(0.2, Qt.yellow) - radial_grad.setColorAt(1, Qt.transparent) + radial_grad.setColorAt(0, Qt.GlobalColor.yellow) + radial_grad.setColorAt(0.2, Qt.GlobalColor.yellow) + radial_grad.setColorAt(1, Qt.GlobalColor.transparent) pixmap = QPixmap(60, 60) - pixmap.fill(Qt.transparent) + pixmap.fill(Qt.GlobalColor.transparent) with QPainter(pixmap) as painter: - painter.setPen(Qt.NoPen) + painter.setPen(Qt.PenStyle.NoPen) painter.setBrush(radial_grad) painter.drawEllipse(0, 0, 60, 60) @@ -66,8 +66,8 @@ class Lighting(QGraphicsView): else: item = QGraphicsRectItem(0, 0, 50, 50) - item.setPen(QPen(Qt.black, 1)) - item.setBrush(QBrush(Qt.white)) + item.setPen(QPen(Qt.GlobalColor.black, 1)) + item.setBrush(QBrush(Qt.GlobalColor.white)) effect = QGraphicsDropShadowEffect(self) effect.setBlurRadius(8) diff --git a/examples/widgets/graphicsview/anchorlayout/anchorlayout.py b/examples/widgets/graphicsview/anchorlayout/anchorlayout.py index 7153018e1..331153122 100644 --- a/examples/widgets/graphicsview/anchorlayout/anchorlayout.py +++ b/examples/widgets/graphicsview/anchorlayout/anchorlayout.py @@ -19,7 +19,7 @@ def create_item(minimum, preferred, maximum, name): w.setMinimumSize(minimum) w.setPreferredSize(preferred) w.setMaximumSize(maximum) - w.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) + w.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Preferred) return w @@ -45,45 +45,45 @@ if __name__ == '__main__': l = QGraphicsAnchorLayout() # noqa: E741 l.setSpacing(0) - w = QGraphicsWidget(None, Qt.Window) + w = QGraphicsWidget(None, Qt.WindowType.Window) w.setPos(20, 20) w.setLayout(l) - # Vertical. - l.addAnchor(a, Qt.AnchorTop, l, Qt.AnchorTop) - l.addAnchor(b, Qt.AnchorTop, l, Qt.AnchorTop) + # Vertical + l.addAnchor(a, Qt.AnchorPoint.AnchorTop, l, Qt.AnchorPoint.AnchorTop) + l.addAnchor(b, Qt.AnchorPoint.AnchorTop, l, Qt.AnchorPoint.AnchorTop) - l.addAnchor(c, Qt.AnchorTop, a, Qt.AnchorBottom) - l.addAnchor(c, Qt.AnchorTop, b, Qt.AnchorBottom) - l.addAnchor(c, Qt.AnchorBottom, d, Qt.AnchorTop) - l.addAnchor(c, Qt.AnchorBottom, e, Qt.AnchorTop) + l.addAnchor(c, Qt.AnchorPoint.AnchorTop, a, Qt.AnchorPoint.AnchorBottom) + l.addAnchor(c, Qt.AnchorPoint.AnchorTop, b, Qt.AnchorPoint.AnchorBottom) + l.addAnchor(c, Qt.AnchorPoint.AnchorBottom, d, Qt.AnchorPoint.AnchorTop) + l.addAnchor(c, Qt.AnchorPoint.AnchorBottom, e, Qt.AnchorPoint.AnchorTop) - l.addAnchor(d, Qt.AnchorBottom, l, Qt.AnchorBottom) - l.addAnchor(e, Qt.AnchorBottom, l, Qt.AnchorBottom) + l.addAnchor(d, Qt.AnchorPoint.AnchorBottom, l, Qt.AnchorPoint.AnchorBottom) + l.addAnchor(e, Qt.AnchorPoint.AnchorBottom, l, Qt.AnchorPoint.AnchorBottom) - l.addAnchor(c, Qt.AnchorTop, f, Qt.AnchorTop) - l.addAnchor(c, Qt.AnchorVerticalCenter, f, Qt.AnchorBottom) - l.addAnchor(f, Qt.AnchorBottom, g, Qt.AnchorTop) - l.addAnchor(c, Qt.AnchorBottom, g, Qt.AnchorBottom) + l.addAnchor(c, Qt.AnchorPoint.AnchorTop, f, Qt.AnchorPoint.AnchorTop) + l.addAnchor(c, Qt.AnchorPoint.AnchorVerticalCenter, f, Qt.AnchorPoint.AnchorBottom) + l.addAnchor(f, Qt.AnchorPoint.AnchorBottom, g, Qt.AnchorPoint.AnchorTop) + l.addAnchor(c, Qt.AnchorPoint.AnchorBottom, g, Qt.AnchorPoint.AnchorBottom) # Horizontal. - l.addAnchor(l, Qt.AnchorLeft, a, Qt.AnchorLeft) - l.addAnchor(l, Qt.AnchorLeft, d, Qt.AnchorLeft) - l.addAnchor(a, Qt.AnchorRight, b, Qt.AnchorLeft) + l.addAnchor(l, Qt.AnchorPoint.AnchorLeft, a, Qt.AnchorPoint.AnchorLeft) + l.addAnchor(l, Qt.AnchorPoint.AnchorLeft, d, Qt.AnchorPoint.AnchorLeft) + l.addAnchor(a, Qt.AnchorPoint.AnchorRight, b, Qt.AnchorPoint.AnchorLeft) - l.addAnchor(a, Qt.AnchorRight, c, Qt.AnchorLeft) - l.addAnchor(c, Qt.AnchorRight, e, Qt.AnchorLeft) + l.addAnchor(a, Qt.AnchorPoint.AnchorRight, c, Qt.AnchorPoint.AnchorLeft) + l.addAnchor(c, Qt.AnchorPoint.AnchorRight, e, Qt.AnchorPoint.AnchorLeft) - l.addAnchor(b, Qt.AnchorRight, l, Qt.AnchorRight) - l.addAnchor(e, Qt.AnchorRight, l, Qt.AnchorRight) - l.addAnchor(d, Qt.AnchorRight, e, Qt.AnchorLeft) + l.addAnchor(b, Qt.AnchorPoint.AnchorRight, l, Qt.AnchorPoint.AnchorRight) + l.addAnchor(e, Qt.AnchorPoint.AnchorRight, l, Qt.AnchorPoint.AnchorRight) + l.addAnchor(d, Qt.AnchorPoint.AnchorRight, e, Qt.AnchorPoint.AnchorLeft) - l.addAnchor(l, Qt.AnchorLeft, f, Qt.AnchorLeft) - l.addAnchor(l, Qt.AnchorLeft, g, Qt.AnchorLeft) - l.addAnchor(f, Qt.AnchorRight, g, Qt.AnchorRight) + l.addAnchor(l, Qt.AnchorPoint.AnchorLeft, f, Qt.AnchorPoint.AnchorLeft) + l.addAnchor(l, Qt.AnchorPoint.AnchorLeft, g, Qt.AnchorPoint.AnchorLeft) + l.addAnchor(f, Qt.AnchorPoint.AnchorRight, g, Qt.AnchorPoint.AnchorRight) scene.addItem(w) - scene.setBackgroundBrush(Qt.darkGreen) + scene.setBackgroundBrush(Qt.GlobalColor.darkGreen) view = QGraphicsView(scene) view.show() diff --git a/examples/widgets/graphicsview/collidingmice/collidingmice.py b/examples/widgets/graphicsview/collidingmice/collidingmice.py index c0f427668..54d256b6a 100644 --- a/examples/widgets/graphicsview/collidingmice/collidingmice.py +++ b/examples/widgets/graphicsview/collidingmice/collidingmice.py @@ -58,12 +58,12 @@ class Mouse(QGraphicsItem): painter.drawEllipse(-10, -20, 20, 40) # Eyes. - painter.setBrush(Qt.white) + painter.setBrush(Qt.GlobalColor.white) painter.drawEllipse(-10, -17, 8, 8) painter.drawEllipse(2, -17, 8, 8) # Nose. - painter.setBrush(Qt.black) + painter.setBrush(Qt.GlobalColor.black) painter.drawEllipse(QRectF(-2, -22, 4, 4)) # Pupils. @@ -72,9 +72,9 @@ class Mouse(QGraphicsItem): # Ears. if self.scene().collidingItems(self): - painter.setBrush(Qt.red) + painter.setBrush(Qt.GlobalColor.red) else: - painter.setBrush(Qt.darkYellow) + painter.setBrush(Qt.GlobalColor.darkYellow) painter.drawEllipse(-17, -12, 16, 16) painter.drawEllipse(1, -12, 16, 16) @@ -84,7 +84,7 @@ class Mouse(QGraphicsItem): path.cubicTo(-5, 22, -5, 22, 0, 25) path.cubicTo(5, 27, 5, 32, 0, 30) path.cubicTo(-5, 32, -5, 42, 0, 35) - painter.setBrush(Qt.NoBrush) + painter.setBrush(Qt.BrushStyle.NoBrush) painter.drawPath(path) def advance(self, phase): @@ -155,7 +155,7 @@ if __name__ == '__main__': scene = QGraphicsScene() scene.setSceneRect(-300, -300, 600, 600) - scene.setItemIndexMethod(QGraphicsScene.NoIndex) + scene.setItemIndexMethod(QGraphicsScene.ItemIndexMethod.NoIndex) for i in range(MOUSE_COUNT): mouse = Mouse() @@ -166,9 +166,9 @@ if __name__ == '__main__': view = QGraphicsView(scene) view.setRenderHint(QPainter.RenderHint.Antialiasing) view.setBackgroundBrush(QBrush(QPixmap(':/images/cheese.jpg'))) - view.setCacheMode(QGraphicsView.CacheBackground) - view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate) - view.setDragMode(QGraphicsView.ScrollHandDrag) + view.setCacheMode(QGraphicsView.CacheModeFlag.CacheBackground) + view.setViewportUpdateMode(QGraphicsView.ViewportUpdateMode.BoundingRectViewportUpdate) + view.setDragMode(QGraphicsView.DragMode.ScrollHandDrag) view.setWindowTitle("Colliding Mice") view.resize(400, 300) view.show() diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.py b/examples/widgets/graphicsview/diagramscene/diagramscene.py index 5cf5edf8b..317113afe 100644 --- a/examples/widgets/graphicsview/diagramscene/diagramscene.py +++ b/examples/widgets/graphicsview/diagramscene/diagramscene.py @@ -30,7 +30,7 @@ class Arrow(QGraphicsLineItem): self._my_start_item = startItem self._my_end_item = endItem self.setFlag(QGraphicsItem.ItemIsSelectable, True) - self._my_color = Qt.black + self._my_color = Qt.GlobalColor.black self.setPen(QPen(self._my_color, 2, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) def set_color(self, color): @@ -122,22 +122,22 @@ class DiagramTextItem(QGraphicsTextItem): def __init__(self, parent=None, scene=None): super().__init__(parent, scene) - self.setFlag(QGraphicsItem.ItemIsMovable) - self.setFlag(QGraphicsItem.ItemIsSelectable) + self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable) + self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsSelectable) def itemChange(self, change, value): - if change == QGraphicsItem.ItemSelectedChange: + if change == QGraphicsItem.GraphicsItemChange.ItemSelectedChange: self.selected_change.emit(self) return value def focusOutEvent(self, event): - self.setTextInteractionFlags(Qt.NoTextInteraction) + self.setTextInteractionFlags(Qt.TextInteractionFlag.NoTextInteraction) self.lost_focus.emit(self) super(DiagramTextItem, self).focusOutEvent(event) def mouseDoubleClickEvent(self, event): - if self.textInteractionFlags() == Qt.NoTextInteraction: - self.setTextInteractionFlags(Qt.TextEditorInteraction) + if self.textInteractionFlags() == Qt.TextInteractionFlag.NoTextInteraction: + self.setTextInteractionFlags(Qt.TextInteractionFlag.TextEditorInteraction) super(DiagramTextItem, self).mouseDoubleClickEvent(event) @@ -178,8 +178,8 @@ class DiagramItem(QGraphicsPolygonItem): QPointF(-120, -80)]) self.setPolygon(self._my_polygon) - self.setFlag(QGraphicsItem.ItemIsMovable, True) - self.setFlag(QGraphicsItem.ItemIsSelectable, True) + self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable, True) + self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsSelectable, True) def remove_arrow(self, arrow): try: @@ -198,9 +198,9 @@ class DiagramItem(QGraphicsPolygonItem): def image(self): pixmap = QPixmap(250, 250) - pixmap.fill(Qt.transparent) + pixmap.fill(Qt.GlobalColor.transparent) with QPainter(pixmap) as painter: - painter.setPen(QPen(Qt.black, 8)) + painter.setPen(QPen(Qt.GlobalColor.black, 8)) painter.translate(125, 125) painter.drawPolyline(self._my_polygon) return pixmap @@ -211,7 +211,7 @@ class DiagramItem(QGraphicsPolygonItem): self._my_context_menu.exec(event.screenPos()) def itemChange(self, change, value): - if change == QGraphicsItem.ItemPositionChange: + if change == QGraphicsItem.GraphicsItemChange.ItemPositionChange: for arrow in self.arrows: arrow.updatePosition() @@ -235,9 +235,9 @@ class DiagramScene(QGraphicsScene): self._my_item_type = DiagramItem.Step self.line = None self._text_item = None - self._my_item_color = Qt.white - self._my_text_color = Qt.black - self._my_line_color = Qt.black + self._my_item_color = Qt.GlobalColor.white + self._my_text_color = Qt.GlobalColor.black + self._my_line_color = Qt.GlobalColor.black self._my_font = QFont() def set_line_color(self, color): @@ -281,7 +281,7 @@ class DiagramScene(QGraphicsScene): item.deleteLater() def mousePressEvent(self, mouseEvent): - if (mouseEvent.button() != Qt.LeftButton): + if (mouseEvent.button() != Qt.MouseButton.LeftButton): return if self._my_mode == self.InsertItem: @@ -297,7 +297,7 @@ class DiagramScene(QGraphicsScene): elif self._my_mode == self.InsertText: text_item = DiagramTextItem() text_item.setFont(self._my_font) - text_item.setTextInteractionFlags(Qt.TextEditorInteraction) + text_item.setTextInteractionFlags(Qt.TextInteractionFlag.TextEditorInteraction) text_item.setZValue(1000.0) text_item.lost_focus.connect(self.editor_lost_focus) text_item.selected_change.connect(self.item_selected) @@ -530,7 +530,7 @@ class MainWindow(QMainWindow): font = item.font() self._font_combo.setCurrentFont(font) self._font_size_combo.setEditText(str(font.pointSize())) - self._bold_action.setChecked(font.weight() == QFont.Bold) + self._bold_action.setChecked(font.weight() == QFont.Weight.Bold) self._italic_action.setChecked(font.italic()) self._underline_action.setChecked(font.underline()) @@ -557,8 +557,8 @@ class MainWindow(QMainWindow): text_button.setIconSize(QSize(50, 50)) text_layout = QGridLayout() - text_layout.addWidget(text_button, 0, 0, Qt.AlignHCenter) - text_layout.addWidget(QLabel("Text"), 1, 0, Qt.AlignCenter) + text_layout.addWidget(text_button, 0, 0, Qt.AlignmentFlag.AlignHCenter) + text_layout.addWidget(QLabel("Text"), 1, 0, Qt.AlignmentFlag.AlignCenter) text_widget = QWidget() text_widget.setLayout(text_layout) layout.addWidget(text_widget, 1, 1) @@ -589,7 +589,8 @@ class MainWindow(QMainWindow): background_widget.setLayout(background_layout) self._tool_box = QToolBox() - self._tool_box.setSizePolicy(QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Ignored)) + self._tool_box.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Maximum, + QSizePolicy.Policy.Ignored)) self._tool_box.setMinimumWidth(item_widget.sizeHint().width()) self._tool_box.addItem(item_widget, "Basic Flowchart Shapes") self._tool_box.addItem(background_widget, "Backgrounds") @@ -659,31 +660,31 @@ class MainWindow(QMainWindow): self._font_size_combo.currentIndexChanged.connect(self.font_size_changed) self._font_color_tool_button = QToolButton() - self._font_color_tool_button.setPopupMode(QToolButton.MenuButtonPopup) + self._font_color_tool_button.setPopupMode(QToolButton.ToolButtonPopupMode.MenuButtonPopup) self._font_color_tool_button.setMenu( - self.create_color_menu(self.text_color_changed, Qt.black)) + self.create_color_menu(self.text_color_changed, Qt.GlobalColor.black)) self._text_action = self._font_color_tool_button.menu().defaultAction() self._font_color_tool_button.setIcon( - self.create_color_tool_button_icon(':/images/textpointer.png', Qt.black)) + self.create_color_tool_button_icon(':/images/textpointer.png', Qt.GlobalColor.black)) self._font_color_tool_button.setAutoFillBackground(True) self._font_color_tool_button.clicked.connect(self.text_button_triggered) self._fill_color_tool_button = QToolButton() - self._fill_color_tool_button.setPopupMode(QToolButton.MenuButtonPopup) + self._fill_color_tool_button.setPopupMode(QToolButton.ToolButtonPopupMode.MenuButtonPopup) self._fill_color_tool_button.setMenu( - self.create_color_menu(self.item_color_changed, Qt.white)) + self.create_color_menu(self.item_color_changed, Qt.GlobalColor.white)) self._fill_action = self._fill_color_tool_button.menu().defaultAction() self._fill_color_tool_button.setIcon( - self.create_color_tool_button_icon(':/images/floodfill.png', Qt.white)) + self.create_color_tool_button_icon(':/images/floodfill.png', Qt.GlobalColor.white)) self._fill_color_tool_button.clicked.connect(self.fill_button_triggered) self._line_color_tool_button = QToolButton() - self._line_color_tool_button.setPopupMode(QToolButton.MenuButtonPopup) + self._line_color_tool_button.setPopupMode(QToolButton.ToolButtonPopupMode.MenuButtonPopup) self._line_color_tool_button.setMenu( - self.create_color_menu(self.line_color_changed, Qt.black)) + self.create_color_menu(self.line_color_changed, Qt.GlobalColor.black)) self._line_action = self._line_color_tool_button.menu().defaultAction() self._line_color_tool_button.setIcon( - self.create_color_tool_button_icon(':/images/linecolor.png', Qt.black)) + self.create_color_tool_button_icon(':/images/linecolor.png', Qt.GlobalColor.black)) self._line_color_tool_button.clicked.connect(self.line_button_triggered) self._text_tool_bar = self.addToolBar("Font") @@ -730,8 +731,8 @@ class MainWindow(QMainWindow): self._background_button_group.addButton(button) layout = QGridLayout() - layout.addWidget(button, 0, 0, Qt.AlignHCenter) - layout.addWidget(QLabel(text), 1, 0, Qt.AlignCenter) + layout.addWidget(button, 0, 0, Qt.AlignmentFlag.AlignHCenter) + layout.addWidget(QLabel(text), 1, 0, Qt.AlignmentFlag.AlignCenter) widget = QWidget() widget.setLayout(layout) @@ -749,8 +750,8 @@ class MainWindow(QMainWindow): self._button_group.addButton(button, diagram_type) layout = QGridLayout() - layout.addWidget(button, 0, 0, Qt.AlignHCenter) - layout.addWidget(QLabel(text), 1, 0, Qt.AlignCenter) + layout.addWidget(button, 0, 0, Qt.AlignmentFlag.AlignHCenter) + layout.addWidget(QLabel(text), 1, 0, Qt.AlignmentFlag.AlignCenter) widget = QWidget() widget.setLayout(layout) @@ -758,7 +759,8 @@ class MainWindow(QMainWindow): return widget def create_color_menu(self, slot, defaultColor): - colors = [Qt.black, Qt.white, Qt.red, Qt.blue, Qt.yellow] + colors = [Qt.GlobalColor.black, Qt.GlobalColor.white, Qt.GlobalColor.red, + Qt.GlobalColor.blue, Qt.GlobalColor.yellow] names = ["black", "white", "red", "blue", "yellow"] color_menu = QMenu(self) @@ -772,7 +774,7 @@ class MainWindow(QMainWindow): def create_color_tool_button_icon(self, imageFile, color): pixmap = QPixmap(50, 80) - pixmap.fill(Qt.transparent) + pixmap.fill(Qt.GlobalColor.transparent) with QPainter(pixmap) as painter: image = QPixmap(imageFile) @@ -787,7 +789,7 @@ class MainWindow(QMainWindow): pixmap = QPixmap(20, 20) with QPainter(pixmap) as painter: - painter.setPen(Qt.NoPen) + painter.setPen(Qt.PenStyle.NoPen) painter.fillRect(QRect(0, 0, 20, 20), color) return QIcon(pixmap) diff --git a/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py b/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py index 75d1c61c4..c25de9131 100644 --- a/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py +++ b/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py @@ -32,29 +32,29 @@ class ColorItem(QGraphicsItem): (r, g, b) = (self.color.red(), self.color.green(), self.color.blue()) self.setToolTip( f"QColor({r}, {g}, {b})\nClick and drag this color onto the robot!") - self.setCursor(Qt.OpenHandCursor) + self.setCursor(Qt.CursorShape.OpenHandCursor) self._start_drag_distance = QApplication.startDragDistance() def boundingRect(self): return QRectF(-15.5, -15.5, 34, 34) def paint(self, painter, option, widget): - painter.setPen(Qt.NoPen) - painter.setBrush(Qt.darkGray) + painter.setPen(Qt.PenStyle.NoPen) + painter.setBrush(Qt.GlobalColor.darkGray) painter.drawEllipse(-12, -12, 30, 30) - painter.setPen(QPen(Qt.black, 1)) + painter.setPen(QPen(Qt.GlobalColor.black, 1)) painter.setBrush(QBrush(self.color)) painter.drawEllipse(-15, -15, 30, 30) def mousePressEvent(self, event): - if event.button() != Qt.LeftButton: + if event.button() != Qt.MouseButton.LeftButton: event.ignore() return - self.setCursor(Qt.ClosedHandCursor) + self.setCursor(Qt.CursorShape.ClosedHandCursor) def mouseMoveEvent(self, event): - start = QPointF(event.buttonDownScreenPos(Qt.LeftButton)) + start = QPointF(event.buttonDownScreenPos(Qt.MouseButton.LeftButton)) if QLineF(event.screenPos(), start).length() < self._start_drag_distance: return @@ -74,7 +74,7 @@ class ColorItem(QGraphicsItem): mime.setText(f"#{r:02x}{g:02x}{b:02x}") pixmap = QPixmap(34, 34) - pixmap.fill(Qt.white) + pixmap.fill(Qt.GlobalColor.white) with QPainter(pixmap) as painter: painter.translate(15, 15) @@ -87,17 +87,17 @@ class ColorItem(QGraphicsItem): drag.setHotSpot(QPoint(15, 20)) drag.exec() - self.setCursor(Qt.OpenHandCursor) + self.setCursor(Qt.CursorShape.OpenHandCursor) def mouseReleaseEvent(self, event): - self.setCursor(Qt.OpenHandCursor) + self.setCursor(Qt.CursorShape.OpenHandCursor) class RobotPart(QGraphicsItem): def __init__(self, parent=None): super().__init__(parent) - self.color = QColor(Qt.lightGray) + self.color = QColor(Qt.GlobalColor.lightGray) self.pixmap = None self._drag_over = False @@ -133,15 +133,15 @@ class RobotHead(RobotPart): def paint(self, painter, option, widget=None): if not self.pixmap: painter.setBrush(self._drag_over and self.color.lighter(130) or self.color) - painter.drawRoundedRect(-10, -30, 20, 30, 25, 25, Qt.RelativeSize) - painter.setBrush(Qt.white) + painter.drawRoundedRect(-10, -30, 20, 30, 25, 25, Qt.SizeMode.RelativeSize) + painter.setBrush(Qt.GlobalColor.white) painter.drawEllipse(-7, -3 - 20, 7, 7) painter.drawEllipse(0, -3 - 20, 7, 7) - painter.setBrush(Qt.black) + painter.setBrush(Qt.GlobalColor.black) painter.drawEllipse(-5, -1 - 20, 2, 2) painter.drawEllipse(2, -1 - 20, 2, 2) - painter.setPen(QPen(Qt.black, 2)) - painter.setBrush(Qt.NoBrush) + painter.setPen(QPen(Qt.GlobalColor.black, 2)) + painter.setBrush(Qt.BrushStyle.NoBrush) painter.drawArc(-6, -2 - 20, 12, 15, 190 * 16, 160 * 16) else: painter.scale(.2272, .2824) @@ -155,7 +155,7 @@ class RobotTorso(RobotPart): def paint(self, painter, option, widget=None): painter.setBrush(self._drag_over and self.color.lighter(130) or self.color) - painter.drawRoundedRect(-20, -20, 40, 60, 25, 25, Qt.RelativeSize) + painter.drawRoundedRect(-20, -20, 40, 60, 25, 25, Qt.SizeMode.RelativeSize) painter.drawEllipse(-25, -20, 20, 20) painter.drawEllipse(5, -20, 20, 20) painter.drawEllipse(-20, 22, 20, 20) @@ -169,7 +169,7 @@ class RobotLimb(RobotPart): def paint(self, painter, option, widget=None): painter.setBrush(self._drag_over and self.color.lighter(130) or self.color) painter.drawRoundedRect(self.boundingRect(), 50, 50, - Qt.RelativeSize) + Qt.SizeMode.RelativeSize) painter.drawEllipse(-5, -5, 10, 10) @@ -215,7 +215,7 @@ class Robot(RobotPart): self.animations[0].setScaleAt(1, 1.1, 1.1) self.timeline.setUpdateInterval(1000 / 25) - curve = QEasingCurve(QEasingCurve.SineCurve) + curve = QEasingCurve(QEasingCurve.Type.SineCurve) self.timeline.setEasingCurve(curve) self.timeline.setLoopCount(0) self.timeline.setDuration(2000) @@ -246,7 +246,7 @@ if __name__ == '__main__': view = QGraphicsView(scene) view.setRenderHint(QPainter.RenderHint.Antialiasing) - view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate) + view.setViewportUpdateMode(QGraphicsView.ViewportUpdateMode.BoundingRectViewportUpdate) view.setBackgroundBrush(QColor(230, 200, 167)) view.setWindowTitle("Drag and Drop Robot") view.show() diff --git a/examples/widgets/graphicsview/elasticnodes/elasticnodes.py b/examples/widgets/graphicsview/elasticnodes/elasticnodes.py index 35607770c..873d3633b 100644 --- a/examples/widgets/graphicsview/elasticnodes/elasticnodes.py +++ b/examples/widgets/graphicsview/elasticnodes/elasticnodes.py @@ -27,7 +27,7 @@ class Edge(QGraphicsItem): self._arrow_size = 10.0 self._source_point = QPointF() self._dest_point = QPointF() - self.setAcceptedMouseButtons(Qt.NoButton) + self.setAcceptedMouseButtons(Qt.MouseButton.NoButton) self.source = weakref.ref(sourceNode) self.dest = weakref.ref(destNode) self.source().add_edge(self) @@ -90,7 +90,8 @@ class Edge(QGraphicsItem): if line.length() == 0.0: return - painter.setPen(QPen(Qt.black, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) + painter.setPen(QPen(Qt.GlobalColor.black, 1, Qt.PenStyle.SolidLine, + Qt.PenCapStyle.RoundCap, Qt.PenJoinStyle.RoundJoin)) painter.drawLine(line) # Draw the arrows if there's enough room. @@ -112,7 +113,7 @@ class Edge(QGraphicsItem): math.cos(angle - math.pi + math.pi / 3) * self._arrow_size) dest_arrow_p2 = self._dest_point + arrow_head2 - painter.setBrush(Qt.black) + painter.setBrush(Qt.GlobalColor.black) painter.drawPolygon(QPolygonF([line.p1(), source_arrow_p1, source_arrow_p2])) painter.drawPolygon(QPolygonF([line.p2(), dest_arrow_p1, dest_arrow_p2])) @@ -125,9 +126,9 @@ class Node(QGraphicsItem): self.graph = weakref.ref(graphWidget) self._edge_list = [] self._new_pos = QPointF() - self.setFlag(QGraphicsItem.ItemIsMovable) - self.setFlag(QGraphicsItem.ItemSendsGeometryChanges) - self.setCacheMode(QGraphicsItem.DeviceCoordinateCache) + self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable) + self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemSendsGeometryChanges) + self.setCacheMode(QGraphicsItem.CacheMode.DeviceCoordinateCache) self.setZValue(-1) def item_type(self): @@ -198,26 +199,26 @@ class Node(QGraphicsItem): return path def paint(self, painter, option, widget): - painter.setPen(Qt.NoPen) - painter.setBrush(Qt.darkGray) + painter.setPen(Qt.PenStyle.NoPen) + painter.setBrush(Qt.GlobalColor.darkGray) painter.drawEllipse(-7, -7, 20, 20) gradient = QRadialGradient(-3, -3, 10) - if option.state & QStyle.State_Sunken: + if option.state & QStyle.StateFlag.State_Sunken: gradient.setCenter(3, 3) gradient.setFocalPoint(3, 3) - gradient.setColorAt(1, QColor(Qt.yellow).lighter(120)) - gradient.setColorAt(0, QColor(Qt.darkYellow).lighter(120)) + gradient.setColorAt(1, QColor(Qt.GlobalColor.yellow).lighter(120)) + gradient.setColorAt(0, QColor(Qt.GlobalColor.darkYellow).lighter(120)) else: - gradient.setColorAt(0, Qt.yellow) - gradient.setColorAt(1, Qt.darkYellow) + gradient.setColorAt(0, Qt.GlobalColor.yellow) + gradient.setColorAt(1, Qt.GlobalColor.darkYellow) painter.setBrush(QBrush(gradient)) - painter.setPen(QPen(Qt.black, 0)) + painter.setPen(QPen(Qt.GlobalColor.black, 0)) painter.drawEllipse(-10, -10, 20, 20) def itemChange(self, change, value): - if change == QGraphicsItem.ItemPositionChange: + if change == QGraphicsItem.GraphicsItemChange.ItemPositionChange: for edge in self._edge_list: edge().adjust() self.graph().item_moved() @@ -240,13 +241,13 @@ class GraphWidget(QGraphicsView): self._timer_id = 0 scene = QGraphicsScene(self) - scene.setItemIndexMethod(QGraphicsScene.NoIndex) + scene.setItemIndexMethod(QGraphicsScene.ItemIndexMethod.NoIndex) scene.setSceneRect(-200, -200, 400, 400) self.setScene(scene) - self.setCacheMode(QGraphicsView.CacheBackground) + self.setCacheMode(QGraphicsView.CacheModeFlag.CacheBackground) self.setRenderHint(QPainter.RenderHint.Antialiasing) - self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse) - self.setResizeAnchor(QGraphicsView.AnchorViewCenter) + self.setTransformationAnchor(QGraphicsView.ViewportAnchor.AnchorUnderMouse) + self.setResizeAnchor(QGraphicsView.ViewportAnchor.AnchorViewCenter) node1 = Node(self) node2 = Node(self) @@ -352,7 +353,7 @@ class GraphWidget(QGraphicsView): # Fill. gradient = QLinearGradient(scene_rect.topLeft(), scene_rect.bottomRight()) - gradient.setColorAt(0, Qt.white) + gradient.setColorAt(0, Qt.GlobalColor.white) gradient.setColorAt(1, Qt.lightGray) painter.fillRect(rect.intersected(scene_rect), QBrush(gradient)) painter.setBrush(Qt.NoBrush) @@ -370,7 +371,7 @@ class GraphWidget(QGraphicsView): painter.setFont(font) painter.setPen(Qt.lightGray) painter.drawText(text_rect.translated(2, 2), message) - painter.setPen(Qt.black) + painter.setPen(Qt.GlobalColor.black) painter.drawText(text_rect, message) def scale_view(self, scaleFactor): diff --git a/examples/widgets/imageviewer/imageviewer.py b/examples/widgets/imageviewer/imageviewer.py index ebf420f92..eb0e1788e 100644 --- a/examples/widgets/imageviewer/imageviewer.py +++ b/examples/widgets/imageviewer/imageviewer.py @@ -33,13 +33,13 @@ class ImageViewer(QMainWindow): self._scale_factor = 1.0 self._first_file_dialog = True self._image_label = QLabel() - self._image_label.setBackgroundRole(QPalette.Base) - self._image_label.setSizePolicy(QSizePolicy.Ignored, - QSizePolicy.Ignored) + self._image_label.setBackgroundRole(QPalette.ColorRole.Base) + self._image_label.setSizePolicy(QSizePolicy.Policy.Ignored, + QSizePolicy.Policy.Ignored) self._image_label.setScaledContents(True) self._scroll_area = QScrollArea() - self._scroll_area.setBackgroundRole(QPalette.Dark) + self._scroll_area.setBackgroundRole(QPalette.ColorRole.Dark) self._scroll_area.setWidget(self._image_label) self._scroll_area.setVisible(False) self.setCentralWidget(self._scroll_area) @@ -73,7 +73,8 @@ class ImageViewer(QMainWindow): def _set_image(self, new_image): self._image = new_image if self._image.colorSpace().isValid(): - self._image.convertToColorSpace(QColorSpace.SRgb) + color_space = QColorSpace(QColorSpace.NamedColorSpace.SRgb) + self._image.convertToColorSpace(color_space) self._image_label.setPixmap(QPixmap.fromImage(self._image)) self._scale_factor = 1.0 @@ -101,16 +102,16 @@ class ImageViewer(QMainWindow): @Slot() def _open(self): dialog = QFileDialog(self, "Open File") - self._initialize_image_filedialog(dialog, QFileDialog.AcceptOpen) - while (dialog.exec() == QDialog.Accepted + self._initialize_image_filedialog(dialog, QFileDialog.AcceptMode.AcceptOpen) + while (dialog.exec() == QDialog.DialogCode.Accepted and not self.load_file(dialog.selectedFiles()[0])): pass @Slot() def _save_as(self): dialog = QFileDialog(self, "Save File As") - self._initialize_image_filedialog(dialog, QFileDialog.AcceptSave) - while (dialog.exec() == QDialog.Accepted + self._initialize_image_filedialog(dialog, QFileDialog.AcceptMode.AcceptSave) + while (dialog.exec() == QDialog.DialogCode.Accepted and not self._save_file(dialog.selectedFiles()[0])): pass @@ -118,7 +119,7 @@ class ImageViewer(QMainWindow): def _print_(self): printer = QPrinter() dialog = QPrintDialog(printer, self) - if dialog.exec() == QDialog.Accepted: + if dialog.exec() == QDialog.DialogCode.Accepted: with QPainter(printer) as painter: pixmap = self._image_label.pixmap() rect = painter.viewport() @@ -176,7 +177,7 @@ class ImageViewer(QMainWindow): self._open_act = file_menu.addAction("&Open...") self._open_act.triggered.connect(self._open) - self._open_act.setShortcut(QKeySequence.Open) + self._open_act.setShortcut(QKeySequence.StandardKey.Open) self._save_as_act = file_menu.addAction("&Save As...") self._save_as_act.triggered.connect(self._save_as) @@ -184,7 +185,7 @@ class ImageViewer(QMainWindow): self._print_act = file_menu.addAction("&Print...") self._print_act.triggered.connect(self._print_) - self._print_act.setShortcut(QKeySequence.Print) + self._print_act.setShortcut(QKeySequence.StandardKey.Print) self._print_act.setEnabled(False) file_menu.addSeparator() @@ -197,23 +198,23 @@ class ImageViewer(QMainWindow): self._copy_act = edit_menu.addAction("&Copy") self._copy_act.triggered.connect(self._copy) - self._copy_act.setShortcut(QKeySequence.Copy) + self._copy_act.setShortcut(QKeySequence.StandardKey.Copy) self._copy_act.setEnabled(False) self._paste_act = edit_menu.addAction("&Paste") self._paste_act.triggered.connect(self._paste) - self._paste_act.setShortcut(QKeySequence.Paste) + self._paste_act.setShortcut(QKeySequence.StandardKey.Paste) view_menu = self.menuBar().addMenu("&View") self._zoom_in_act = view_menu.addAction("Zoom &In (25%)") - self._zoom_in_act.setShortcut(QKeySequence.ZoomIn) + self._zoom_in_act.setShortcut(QKeySequence.StandardKey.ZoomIn) self._zoom_in_act.triggered.connect(self._zoom_in) self._zoom_in_act.setEnabled(False) self._zoom_out_act = view_menu.addAction("Zoom &Out (25%)") self._zoom_out_act.triggered.connect(self._zoom_out) - self._zoom_out_act.setShortcut(QKeySequence.ZoomOut) + self._zoom_out_act.setShortcut(QKeySequence.StandardKey.ZoomOut) self._zoom_out_act.setEnabled(False) self._normal_size_act = view_menu.addAction("&Normal Size") @@ -264,7 +265,7 @@ class ImageViewer(QMainWindow): def _initialize_image_filedialog(self, dialog, acceptMode): if self._first_file_dialog: self._first_file_dialog = False - locations = QStandardPaths.standardLocations(QStandardPaths.PicturesLocation) + locations = QStandardPaths.standardLocations(QStandardPaths.StandardLocation.PicturesLocation) # noqa: E501 directory = locations[-1] if locations else QDir.currentPath() dialog.setDirectory(directory) @@ -274,5 +275,5 @@ class ImageViewer(QMainWindow): dialog.setMimeTypeFilters(mime_types) dialog.selectMimeTypeFilter("image/jpeg") dialog.setAcceptMode(acceptMode) - if acceptMode == QFileDialog.AcceptSave: + if acceptMode == QFileDialog.AcceptMode.AcceptSave: dialog.setDefaultSuffix("jpg") diff --git a/examples/widgets/itemviews/address_book/adddialogwidget.py b/examples/widgets/itemviews/address_book/adddialogwidget.py index 29d0a4756..cd850bed0 100644 --- a/examples/widgets/itemviews/address_book/adddialogwidget.py +++ b/examples/widgets/itemviews/address_book/adddialogwidget.py @@ -16,8 +16,8 @@ class AddDialogWidget(QDialog): name_label = QLabel("Name") address_label = QLabel("Address") - button_box = QDialogButtonBox(QDialogButtonBox.Ok - | QDialogButtonBox.Cancel) + button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok + | QDialogButtonBox.StandardButton.Cancel) self._name_text = QLineEdit() self._address_text = QTextEdit() @@ -26,8 +26,8 @@ class AddDialogWidget(QDialog): grid.setColumnStretch(1, 2) grid.addWidget(name_label, 0, 0) grid.addWidget(self._name_text, 0, 1) - grid.addWidget(address_label, 1, 0, Qt.AlignLeft | Qt.AlignTop) - grid.addWidget(self._address_text, 1, 1, Qt.AlignLeft) + grid.addWidget(address_label, 1, 0, Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop) + grid.addWidget(self._address_text, 1, 1, Qt.AlignmentFlag.AlignLeft) layout = QVBoxLayout() layout.addLayout(grid) diff --git a/examples/widgets/itemviews/address_book/addresswidget.py b/examples/widgets/itemviews/address_book/addresswidget.py index a584dcbea..37bd06f85 100644 --- a/examples/widgets/itemviews/address_book/addresswidget.py +++ b/examples/widgets/itemviews/address_book/addresswidget.py @@ -149,11 +149,11 @@ class AddressWidget(QTabWidget): table_view = QTableView() table_view.setModel(proxy_model) table_view.setSortingEnabled(True) - table_view.setSelectionBehavior(QAbstractItemView.SelectRows) + table_view.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) table_view.horizontalHeader().setStretchLastSection(True) table_view.verticalHeader().hide() - table_view.setEditTriggers(QAbstractItemView.NoEditTriggers) - table_view.setSelectionMode(QAbstractItemView.SingleSelection) + table_view.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers) + table_view.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) # This here be the magic: we use the group name (e.g. "ABC") to # build the regex for the QSortFilterProxyModel for the group's @@ -162,10 +162,10 @@ class AddressWidget(QTabWidget): # "A", "B", or "C". Notice that we set it to be case-insensitive. re = QRegularExpression(f"^[{group}].*") assert re.isValid() - re.setPatternOptions(QRegularExpression.CaseInsensitiveOption) + re.setPatternOptions(QRegularExpression.PatternOption.CaseInsensitiveOption) proxy_model.setFilterRegularExpression(re) proxy_model.setFilterKeyColumn(0) # Filter on the "name" column - proxy_model.sort(0, Qt.AscendingOrder) + proxy_model.sort(0, Qt.SortOrder.AscendingOrder) # This prevents an application crash (see: # https://www.qtcentre.org/threads/58874-QListView-SelectionModel-selectionChanged-Crash) # noqa: E501 diff --git a/examples/widgets/itemviews/address_book/newaddresstab.py b/examples/widgets/itemviews/address_book/newaddresstab.py index 055137db9..414101764 100644 --- a/examples/widgets/itemviews/address_book/newaddresstab.py +++ b/examples/widgets/itemviews/address_book/newaddresstab.py @@ -26,7 +26,7 @@ class NewAddressTab(QWidget): layout = QVBoxLayout() layout.addWidget(description_label) - layout.addWidget(add_button, 0, Qt.AlignCenter) + layout.addWidget(add_button, 0, Qt.AlignmentFlag.AlignCenter) self.setLayout(layout) diff --git a/examples/widgets/itemviews/address_book/tablemodel.py b/examples/widgets/itemviews/address_book/tablemodel.py index 8e9f5b76a..6654edfad 100644 --- a/examples/widgets/itemviews/address_book/tablemodel.py +++ b/examples/widgets/itemviews/address_book/tablemodel.py @@ -105,6 +105,6 @@ class TableModel(QAbstractTableModel): manually adjust each tableView to have NoEditTriggers. """ if not index.isValid(): - return Qt.ItemIsEnabled + return Qt.ItemFlag.ItemIsEnabled return Qt.ItemFlags(QAbstractTableModel.flags(self, index) - | Qt.ItemIsEditable) + | Qt.ItemFlag.ItemIsEditable) diff --git a/examples/widgets/itemviews/fetchmore/fetchmore.py b/examples/widgets/itemviews/fetchmore/fetchmore.py index c1c84f0f2..8f41910aa 100644 --- a/examples/widgets/itemviews/fetchmore/fetchmore.py +++ b/examples/widgets/itemviews/fetchmore/fetchmore.py @@ -81,8 +81,8 @@ class FileListModel(QAbstractListModel): directory = QDir(path) self.beginResetModel() - directory_filter = QDir.AllEntries | QDir.NoDot - self._file_list = directory.entryInfoList(directory_filter, QDir.Name) + directory_filter = QDir.Filter.AllEntries | QDir.Filter.NoDot + self._file_list = directory.entryInfoList(directory_filter, QDir.SortFlag.Name) self._file_count = 0 self.endResetModel() @@ -101,8 +101,8 @@ class Window(QWidget): self._view.setModel(self._model) self._log_viewer = QPlainTextEdit() - self._log_viewer.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, - QSizePolicy.Preferred)) + self._log_viewer.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Preferred, + QSizePolicy.Policy.Preferred)) self._model.number_populated.connect(self.update_log) self._view.activated.connect(self.activated) diff --git a/examples/widgets/itemviews/stardelegate/stardelegate.py b/examples/widgets/itemviews/stardelegate/stardelegate.py index 394bfc98f..93b09cdff 100644 --- a/examples/widgets/itemviews/stardelegate/stardelegate.py +++ b/examples/widgets/itemviews/stardelegate/stardelegate.py @@ -34,7 +34,7 @@ class StarDelegate(QStyledItemDelegate): # If the row is currently selected, we need to make sure we # paint the background accordingly. - if option.state & QStyle.State_Selected: + if option.state & QStyle.StateFlag.State_Selected: # The original C++ example used option.palette.foreground() to # get the brush for painting, but there are a couple of # problems with that: @@ -112,9 +112,9 @@ if __name__ == "__main__": # Create and populate the tableWidget table_widget = QTableWidget(4, 4) table_widget.setItemDelegate(StarDelegate()) - table_widget.setEditTriggers(QAbstractItemView.DoubleClicked - | QAbstractItemView.SelectedClicked) - table_widget.setSelectionBehavior(QAbstractItemView.SelectRows) + table_widget.setEditTriggers(QAbstractItemView.EditTrigger.DoubleClicked + | QAbstractItemView.EditTrigger.SelectedClicked) + table_widget.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) table_widget.setHorizontalHeaderLabels(["Title", "Genre", "Artist", "Rating"]) data = [["Mass in B-Minor", "Baroque", "J.S. Bach", 5], diff --git a/examples/widgets/itemviews/stardelegate/starrating.py b/examples/widgets/itemviews/stardelegate/starrating.py index 38faade64..694bb43eb 100644 --- a/examples/widgets/itemviews/stardelegate/starrating.py +++ b/examples/widgets/itemviews/stardelegate/starrating.py @@ -42,7 +42,7 @@ class StarRating: painter.save() painter.setRenderHint(QPainter.RenderHint.Antialiasing, True) - painter.setPen(Qt.NoPen) + painter.setPen(Qt.PenStyle.NoPen) if isEditable: painter.setBrush(palette.highlight()) @@ -55,7 +55,7 @@ class StarRating: for i in range(self.MAX_STAR_COUNT): if i < self.star_count: - painter.drawPolygon(self._star_polygon, Qt.WindingFill) + painter.drawPolygon(self._star_polygon, Qt.FillRule.WindingFill) elif isEditable: painter.drawPolygon(self._diamond_polygon, Qt.WindingFill) painter.translate(1.0, 0.0) diff --git a/examples/widgets/layouts/basiclayouts/basiclayouts.py b/examples/widgets/layouts/basiclayouts/basiclayouts.py index be99d804f..949adc677 100644 --- a/examples/widgets/layouts/basiclayouts/basiclayouts.py +++ b/examples/widgets/layouts/basiclayouts/basiclayouts.py @@ -30,7 +30,8 @@ class Dialog(QDialog): big_editor.setPlainText("This widget takes up all the remaining space " "in the top-level layout.") - button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok + | QDialogButtonBox.StandardButton.Cancel) button_box.accepted.connect(self.accept) button_box.rejected.connect(self.reject) diff --git a/examples/widgets/layouts/borderlayout/borderlayout.py b/examples/widgets/layouts/borderlayout/borderlayout.py index ac62a4163..e60c2465f 100644 --- a/examples/widgets/layouts/borderlayout/borderlayout.py +++ b/examples/widgets/layouts/borderlayout/borderlayout.py @@ -63,7 +63,7 @@ class BorderLayout(QLayout): self.add(QWidgetItem(widget), position) def expandingDirections(self) -> Qt.Orientations: - return Qt.Orientation.Horizontal | Qt.Vertical + return Qt.Orientation.Horizontal | Qt.Orientation.Vertical def hasHeightForWidth(self) -> bool: return False @@ -238,7 +238,7 @@ class Window(QWidget): @staticmethod def create_label(text: str): label = QLabel(text) - label.setFrameStyle(QFrame.Box | QFrame.Raised) + label.setFrameStyle(QFrame.Shape.Box | QFrame.Shadow.Raised) return label diff --git a/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.py b/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.py index 268e2056f..bff66727f 100644 --- a/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.py +++ b/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.py @@ -26,7 +26,7 @@ class Dialog(QDialog): main_layout.addWidget(self._rotable_group_box, 0, 0) main_layout.addWidget(self._options_group_box, 1, 0) main_layout.addWidget(self._button_box, 2, 0) - main_layout.setSizeConstraint(QLayout.SetMinimumSize) + main_layout.setSizeConstraint(QLayout.SizeConstraint.SetMinimumSize) self._main_layout = main_layout self.setLayout(self._main_layout) @@ -102,7 +102,7 @@ class Dialog(QDialog): buttons_orientation_combo_box = QComboBox() buttons_orientation_combo_box.addItem("Horizontal", Qt.Orientation.Horizontal) - buttons_orientation_combo_box.addItem("Vertical", Qt.Vertical) + buttons_orientation_combo_box.addItem("Vertical", Qt.Orientation.Vertical) buttons_orientation_combo_box.currentIndexChanged[int].connect( self.buttons_orientation_changed) @@ -117,10 +117,10 @@ class Dialog(QDialog): def create_button_box(self): self._button_box = QDialogButtonBox() - close_button = self._button_box.addButton(QDialogButtonBox.Close) - help_button = self._button_box.addButton(QDialogButtonBox.Help) + close_button = self._button_box.addButton(QDialogButtonBox.StandardButton.Close) + help_button = self._button_box.addButton(QDialogButtonBox.StandardButton.Help) rotate_widgets_button = self._button_box.addButton( - "Rotate &Widgets", QDialogButtonBox.ActionRole) + "Rotate &Widgets", QDialogButtonBox.ButtonRole.ActionRole) rotate_widgets_button.clicked.connect(self.rotate_widgets) close_button.clicked.connect(self.close) diff --git a/examples/widgets/mainwindows/dockwidgets/dockwidgets.py b/examples/widgets/mainwindows/dockwidgets/dockwidgets.py index d0917063f..95c8ba1f9 100644 --- a/examples/widgets/mainwindows/dockwidgets/dockwidgets.py +++ b/examples/widgets/mainwindows/dockwidgets/dockwidgets.py @@ -40,7 +40,7 @@ class MainWindow(QMainWindow): self._text_edit.clear() cursor = self._text_edit.textCursor() - cursor.movePosition(QTextCursor.Start) + cursor.movePosition(QTextCursor.MoveOperation.Start) top_frame = cursor.currentFrame() top_frame_format = top_frame.frameFormat() top_frame_format.setPadding(16) @@ -48,14 +48,14 @@ class MainWindow(QMainWindow): text_format = QTextCharFormat() bold_format = QTextCharFormat() - bold_format.setFontWeight(QFont.Bold) + bold_format.setFontWeight(QFont.Weight.Bold) italic_format = QTextCharFormat() italic_format.setFontItalic(True) table_format = QTextTableFormat() table_format.setBorder(1) table_format.setCellPadding(16) - table_format.setAlignment(Qt.AlignRight) + table_format.setAlignment(Qt.AlignmentFlag.AlignRight) cursor.insertTable(1, 1, table_format) cursor.insertText("The Firm", bold_format) cursor.insertBlock() @@ -95,9 +95,9 @@ class MainWindow(QMainWindow): def save(self): dialog = QFileDialog(self, "Choose a file name") dialog.setMimeTypeFilters(['text/html']) - dialog.setAcceptMode(QFileDialog.AcceptSave) + dialog.setAcceptMode(QFileDialog.AcceptMode.AcceptSave) dialog.setDefaultSuffix('html') - if dialog.exec() != QDialog.Accepted: + if dialog.exec() != QDialog.DialogCode.Accepted: return filename = dialog.selectedFiles()[0] @@ -162,24 +162,24 @@ class MainWindow(QMainWindow): def create_actions(self): icon = QIcon.fromTheme('document-new', QIcon(':/images/new.png')) self._new_letter_act = QAction(icon, "&New Letter", - self, shortcut=QKeySequence.New, + self, shortcut=QKeySequence.StandardKey.New, statusTip="Create a new form letter", triggered=self.new_letter) icon = QIcon.fromTheme('document-save', QIcon(':/images/save.png')) self._save_act = QAction(icon, "&Save...", self, - shortcut=QKeySequence.Save, + shortcut=QKeySequence.StandardKey.Save, statusTip="Save the current form letter", triggered=self.save) icon = QIcon.fromTheme('document-print', QIcon(':/images/print.png')) self._print_act = QAction(icon, "&Print...", self, - shortcut=QKeySequence.Print, + shortcut=QKeySequence.StandardKey.Print, statusTip="Print the current form letter", triggered=self.print_) icon = QIcon.fromTheme('edit-undo', QIcon(':/images/undo.png')) self._undo_act = QAction(icon, "&Undo", self, - shortcut=QKeySequence.Undo, + shortcut=QKeySequence.StandardKey.Undo, statusTip="Undo the last editing action", triggered=self.undo) self._quit_act = QAction("&Quit", self, shortcut="Ctrl+Q", @@ -226,7 +226,8 @@ class MainWindow(QMainWindow): def create_dock_windows(self): dock = QDockWidget("Customers", self) - dock.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea) + dock.setAllowedAreas(Qt.DockWidgetArea.LeftDockWidgetArea + | Qt.DockWidgetArea.RightDockWidgetArea) self._customer_list = QListWidget(dock) self._customer_list.addItems(( "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton", @@ -236,7 +237,7 @@ class MainWindow(QMainWindow): "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston", "Sally Hobart, Tiroli Tea, 67 Long River, Fedula")) dock.setWidget(self._customer_list) - self.addDockWidget(Qt.RightDockWidgetArea, dock) + self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, dock) self._view_menu.addAction(dock.toggleViewAction()) dock = QDockWidget("Paragraphs", self) @@ -260,7 +261,7 @@ class MainWindow(QMainWindow): "You made an overpayment (more than $5). Do you wish to buy more " "items, or should we return the excess to you?")) dock.setWidget(self._paragraphs_list) - self.addDockWidget(Qt.RightDockWidgetArea, dock) + self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, dock) self._view_menu.addAction(dock.toggleViewAction()) self._customer_list.currentTextChanged.connect(self.insert_customer) diff --git a/examples/widgets/mainwindows/mdi/mdi.py b/examples/widgets/mainwindows/mdi/mdi.py index e41200ca1..341a7f4de 100644 --- a/examples/widgets/mainwindows/mdi/mdi.py +++ b/examples/widgets/mainwindows/mdi/mdi.py @@ -24,7 +24,7 @@ class MdiChild(QTextEdit): def __init__(self): super().__init__() - self.setAttribute(Qt.WA_DeleteOnClose) + self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose) self._is_untitled = True def new_file(self): @@ -37,14 +37,14 @@ class MdiChild(QTextEdit): def load_file(self, fileName): file = QFile(fileName) - if not file.open(QFile.ReadOnly | QFile.Text): + if not file.open(QFile.OpenModeFlag.ReadOnly | QFile.OpenModeFlag.Text): reason = file.errorString() message = f"Cannot read file {fileName}:\n{reason}." QMessageBox.warning(self, "MDI", message) return False instr = QTextStream(file) - with QApplication.setOverrideCursor(Qt.WaitCursor): + with QApplication.setOverrideCursor(Qt.CursorShape.WaitCursor): self.setPlainText(instr.readAll()) self.set_current_file(fileName) @@ -68,9 +68,9 @@ class MdiChild(QTextEdit): def save_file(self, fileName): error = None - with QApplication.setOverrideCursor(Qt.WaitCursor): + with QApplication.setOverrideCursor(Qt.CursorShape.WaitCursor): file = QSaveFile(fileName) - if file.open(QFile.WriteOnly | QFile.Text): + if file.open(QFile.OpenModeFlag.WriteOnly | QFile.OpenModeFlag.Text): outstr = QTextStream(file) outstr << self.toPlainText() if not file.commit(): @@ -133,8 +133,8 @@ class MainWindow(QMainWindow): super().__init__() self._mdi_area = QMdiArea() - self._mdi_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) - self._mdi_area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) + self._mdi_area.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) + self._mdi_area.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded) self.setCentralWidget(self._mdi_area) self._mdi_area.subWindowActivated.connect(self.update_menus) @@ -273,45 +273,43 @@ class MainWindow(QMainWindow): def create_actions(self): icon = QIcon.fromTheme(QIcon.ThemeIcon.DocumentNew) - self._new_act = QAction(icon, "&New", self, - shortcut=QKeySequence.New, statusTip="Create a new file", - triggered=self.new_file) + self._new_act = QAction(icon, "&New", self, shortcut=QKeySequence.StandardKey.New, + statusTip="Create a new file", triggered=self.new_file) icon = QIcon.fromTheme(QIcon.ThemeIcon.DocumentOpen) - self._open_act = QAction(icon, "&Open...", self, - shortcut=QKeySequence.Open, statusTip="Open an existing file", - triggered=self.open) + self._open_act = QAction(icon, "&Open...", self, shortcut=QKeySequence.StandardKey.Open, + statusTip="Open an existing file", triggered=self.open) icon = QIcon.fromTheme(QIcon.ThemeIcon.DocumentSave) self._save_act = QAction(icon, "&Save", self, - shortcut=QKeySequence.Save, + shortcut=QKeySequence.StandardKey.Save, statusTip="Save the document to disk", triggered=self.save) self._save_as_act = QAction("Save &As...", self, - shortcut=QKeySequence.SaveAs, + shortcut=QKeySequence.StandardKey.SaveAs, statusTip="Save the document under a new name", triggered=self.save_as) icon = QIcon.fromTheme(QIcon.ThemeIcon.ApplicationExit) - self._exit_act = QAction(icon, "E&xit", self, shortcut=QKeySequence.Quit, + self._exit_act = QAction(icon, "E&xit", self, shortcut=QKeySequence.StandardKey.Quit, statusTip="Exit the application", triggered=QApplication.instance().closeAllWindows) icon = QIcon.fromTheme(QIcon.ThemeIcon.EditCut) self._cut_act = QAction(icon, "Cu&t", self, - shortcut=QKeySequence.Cut, + shortcut=QKeySequence.StandardKey.Cut, statusTip="Cut the current selection's contents to the clipboard", triggered=self.cut) icon = QIcon.fromTheme(QIcon.ThemeIcon.EditCopy) self._copy_act = QAction(icon, "&Copy", self, - shortcut=QKeySequence.Copy, + shortcut=QKeySequence.StandardKey.Copy, statusTip="Copy the current selection's contents to the clipboard", triggered=self.copy) icon = QIcon.fromTheme(QIcon.ThemeIcon.EditPaste) self._paste_act = QAction(icon, "&Paste", self, - shortcut=QKeySequence.Paste, + shortcut=QKeySequence.StandardKey.Paste, statusTip="Paste the clipboard's contents into the current " "selection", triggered=self.paste) @@ -331,12 +329,12 @@ class MainWindow(QMainWindow): statusTip="Cascade the windows", triggered=self._mdi_area.cascadeSubWindows) - self._next_act = QAction("Ne&xt", self, shortcut=QKeySequence.NextChild, + self._next_act = QAction("Ne&xt", self, shortcut=QKeySequence.StandardKey.NextChild, statusTip="Move the focus to the next window", triggered=self._mdi_area.activateNextSubWindow) self._previous_act = QAction("Pre&vious", self, - shortcut=QKeySequence.PreviousChild, + shortcut=QKeySequence.StandardKey.PreviousChild, statusTip="Move the focus to the previous window", triggered=self._mdi_area.activatePreviousSubWindow) diff --git a/examples/widgets/painting/basicdrawing/basicdrawing.py b/examples/widgets/painting/basicdrawing/basicdrawing.py index 75fdffad6..ef4af5d85 100644 --- a/examples/widgets/painting/basicdrawing/basicdrawing.py +++ b/examples/widgets/painting/basicdrawing/basicdrawing.py @@ -38,7 +38,7 @@ class RenderArea(QWidget): self.transformed = False self.pixmap.load(':/images/qt-logo.png') - self.setBackgroundRole(QPalette.Base) + self.setBackgroundRole(QPalette.ColorRole.Base) self.setAutoFillBackground(True) def minimumSizeHint(self): @@ -105,7 +105,7 @@ class RenderArea(QWidget): elif self.shape == RenderArea.Rect: painter.drawRect(rect) elif self.shape == RenderArea.RoundedRect: - painter.drawRoundedRect(rect, 25, 25, Qt.RelativeSize) + painter.drawRoundedRect(rect, 25, 25, Qt.SizeMode.RelativeSize) elif self.shape == RenderArea.Ellipse: painter.drawEllipse(rect) elif self.shape == RenderArea.Arc: @@ -118,7 +118,7 @@ class RenderArea(QWidget): painter.drawPath(path) elif self.shape == RenderArea.Text: qv = qVersion() - painter.drawText(rect, Qt.AlignCenter, + painter.drawText(rect, Qt.AlignmentFlag.AlignCenter, f"PySide 6\nQt {qv}") elif self.shape == RenderArea.Pixmap: painter.drawPixmap(10, 10, self.pixmap) @@ -126,7 +126,7 @@ class RenderArea(QWidget): painter.restore() painter.setPen(self.palette().dark().color()) - painter.setBrush(Qt.NoBrush) + painter.setBrush(Qt.BrushStyle.NoBrush) painter.drawRect(QRect(0, 0, self.width() - 1, self.height() - 1)) @@ -165,52 +165,53 @@ class Window(QWidget): pen_width_label.setBuddy(self._pen_width_spin_box) self._pen_style_combo_box = QComboBox() - self._pen_style_combo_box.addItem("Solid", Qt.SolidLine) - self._pen_style_combo_box.addItem("Dash", Qt.DashLine) - self._pen_style_combo_box.addItem("Dot", Qt.DotLine) - self._pen_style_combo_box.addItem("Dash Dot", Qt.DashDotLine) - self._pen_style_combo_box.addItem("Dash Dot Dot", Qt.DashDotDotLine) - self._pen_style_combo_box.addItem("None", Qt.NoPen) + self._pen_style_combo_box.addItem("Solid", Qt.PenStyle.SolidLine) + self._pen_style_combo_box.addItem("Dash", Qt.PenStyle.DashLine) + self._pen_style_combo_box.addItem("Dot", Qt.PenStyle.DotLine) + self._pen_style_combo_box.addItem("Dash Dot", Qt.PenStyle.DashDotLine) + self._pen_style_combo_box.addItem("Dash Dot Dot", Qt.PenStyle.DashDotDotLine) + self._pen_style_combo_box.addItem("None", Qt.PenStyle.NoPen) pen_style_label = QLabel("&Pen Style:") pen_style_label.setBuddy(self._pen_style_combo_box) self._pen_cap_combo_box = QComboBox() - self._pen_cap_combo_box.addItem("Flat", Qt.FlatCap) - self._pen_cap_combo_box.addItem("Square", Qt.SquareCap) - self._pen_cap_combo_box.addItem("Round", Qt.RoundCap) + self._pen_cap_combo_box.addItem("Flat", Qt.PenCapStyle.FlatCap) + self._pen_cap_combo_box.addItem("Square", Qt.PenCapStyle.SquareCap) + self._pen_cap_combo_box.addItem("Round", Qt.PenCapStyle.RoundCap) pen_cap_label = QLabel("Pen &Cap:") pen_cap_label.setBuddy(self._pen_cap_combo_box) self._pen_join_combo_box = QComboBox() - self._pen_join_combo_box.addItem("Miter", Qt.MiterJoin) - self._pen_join_combo_box.addItem("Bevel", Qt.BevelJoin) - self._pen_join_combo_box.addItem("Round", Qt.RoundJoin) + self._pen_join_combo_box.addItem("Miter", Qt.PenJoinStyle.MiterJoin) + self._pen_join_combo_box.addItem("Bevel", Qt.PenJoinStyle.BevelJoin) + self._pen_join_combo_box.addItem("Round", Qt.PenJoinStyle.RoundJoin) pen_join_label = QLabel("Pen &Join:") pen_join_label.setBuddy(self._pen_join_combo_box) self._brush_style_combo_box = QComboBox() - self._brush_style_combo_box.addItem("Linear Gradient", Qt.LinearGradientPattern) - self._brush_style_combo_box.addItem("Radial Gradient", Qt.RadialGradientPattern) - self._brush_style_combo_box.addItem("Conical Gradient", Qt.ConicalGradientPattern) - self._brush_style_combo_box.addItem("Texture", Qt.TexturePattern) - self._brush_style_combo_box.addItem("Solid", Qt.SolidPattern) - self._brush_style_combo_box.addItem("Horizontal", Qt.HorPattern) - self._brush_style_combo_box.addItem("Vertical", Qt.VerPattern) - self._brush_style_combo_box.addItem("Cross", Qt.CrossPattern) - self._brush_style_combo_box.addItem("Backward Diagonal", Qt.BDiagPattern) - self._brush_style_combo_box.addItem("Forward Diagonal", Qt.FDiagPattern) - self._brush_style_combo_box.addItem("Diagonal Cross", Qt.DiagCrossPattern) - self._brush_style_combo_box.addItem("Dense 1", Qt.Dense1Pattern) - self._brush_style_combo_box.addItem("Dense 2", Qt.Dense2Pattern) - self._brush_style_combo_box.addItem("Dense 3", Qt.Dense3Pattern) - self._brush_style_combo_box.addItem("Dense 4", Qt.Dense4Pattern) - self._brush_style_combo_box.addItem("Dense 5", Qt.Dense5Pattern) - self._brush_style_combo_box.addItem("Dense 6", Qt.Dense6Pattern) - self._brush_style_combo_box.addItem("Dense 7", Qt.Dense7Pattern) - self._brush_style_combo_box.addItem("None", Qt.NoBrush) + self._brush_style_combo_box.addItem("Linear Gradient", Qt.BrushStyle.LinearGradientPattern) + self._brush_style_combo_box.addItem("Radial Gradient", Qt.BrushStyle.RadialGradientPattern) + self._brush_style_combo_box.addItem("Conical Gradient", + Qt.BrushStyle.ConicalGradientPattern) + self._brush_style_combo_box.addItem("Texture", Qt.BrushStyle.TexturePattern) + self._brush_style_combo_box.addItem("Solid", Qt.BrushStyle.SolidPattern) + self._brush_style_combo_box.addItem("Horizontal", Qt.BrushStyle.HorPattern) + self._brush_style_combo_box.addItem("Vertical", Qt.BrushStyle.VerPattern) + self._brush_style_combo_box.addItem("Cross", Qt.BrushStyle.CrossPattern) + self._brush_style_combo_box.addItem("Backward Diagonal", Qt.BrushStyle.BDiagPattern) + self._brush_style_combo_box.addItem("Forward Diagonal", Qt.BrushStyle.FDiagPattern) + self._brush_style_combo_box.addItem("Diagonal Cross", Qt.BrushStyle.DiagCrossPattern) + self._brush_style_combo_box.addItem("Dense 1", Qt.BrushStyle.Dense1Pattern) + self._brush_style_combo_box.addItem("Dense 2", Qt.BrushStyle.Dense2Pattern) + self._brush_style_combo_box.addItem("Dense 3", Qt.BrushStyle.Dense3Pattern) + self._brush_style_combo_box.addItem("Dense 4", Qt.BrushStyle.Dense4Pattern) + self._brush_style_combo_box.addItem("Dense 5", Qt.BrushStyle.Dense5Pattern) + self._brush_style_combo_box.addItem("Dense 6", Qt.BrushStyle.Dense6Pattern) + self._brush_style_combo_box.addItem("Dense 7", Qt.BrushStyle.Dense7Pattern) + self._brush_style_combo_box.addItem("None", Qt.BrushStyle.NoBrush) brush_style_label = QLabel("&Brush Style:") brush_style_label.setBuddy(self._brush_style_combo_box) @@ -233,20 +234,20 @@ class Window(QWidget): main_layout.setColumnStretch(3, 1) main_layout.addWidget(self._render_area, 0, 0, 1, 4) main_layout.setRowMinimumHeight(1, 6) - main_layout.addWidget(shape_label, 2, 1, Qt.AlignRight) + main_layout.addWidget(shape_label, 2, 1, Qt.AlignmentFlag.AlignRight) main_layout.addWidget(self._shape_combo_box, 2, 2) - main_layout.addWidget(pen_width_label, 3, 1, Qt.AlignRight) + main_layout.addWidget(pen_width_label, 3, 1, Qt.AlignmentFlag.AlignRight) main_layout.addWidget(self._pen_width_spin_box, 3, 2) - main_layout.addWidget(pen_style_label, 4, 1, Qt.AlignRight) + main_layout.addWidget(pen_style_label, 4, 1, Qt.AlignmentFlag.AlignRight) main_layout.addWidget(self._pen_style_combo_box, 4, 2) - main_layout.addWidget(pen_cap_label, 5, 1, Qt.AlignRight) + main_layout.addWidget(pen_cap_label, 5, 1, Qt.AlignmentFlag.AlignRight) main_layout.addWidget(self._pen_cap_combo_box, 5, 2) - main_layout.addWidget(pen_join_label, 6, 1, Qt.AlignRight) + main_layout.addWidget(pen_join_label, 6, 1, Qt.AlignmentFlag.AlignRight) main_layout.addWidget(self._pen_join_combo_box, 6, 2) - main_layout.addWidget(brush_style_label, 7, 1, Qt.AlignRight) + main_layout.addWidget(brush_style_label, 7, 1, Qt.AlignmentFlag.AlignRight) main_layout.addWidget(self._brush_style_combo_box, 7, 2) main_layout.setRowMinimumHeight(8, 6) - main_layout.addWidget(other_options_label, 9, 1, Qt.AlignRight) + main_layout.addWidget(other_options_label, 9, 1, Qt.AlignmentFlag.AlignRight) main_layout.addWidget(self._antialiasing_check_box, 9, 2) main_layout.addWidget(self._transformations_check_box, 10, 2) self.setLayout(main_layout) @@ -271,34 +272,34 @@ class Window(QWidget): join = Qt.PenJoinStyle(self._pen_join_combo_box.itemData( self._pen_join_combo_box.currentIndex(), id_role)) - self._render_area.set_pen(QPen(Qt.blue, width, style, cap, join)) + self._render_area.set_pen(QPen(Qt.GlobalColor.blue, width, style, cap, join)) def brush_changed(self): style = Qt.BrushStyle(self._brush_style_combo_box.itemData( self._brush_style_combo_box.currentIndex(), id_role)) - if style == Qt.LinearGradientPattern: + if style == Qt.BrushStyle.LinearGradientPattern: linear_gradient = QLinearGradient(0, 0, 100, 100) - linear_gradient.setColorAt(0.0, Qt.white) - linear_gradient.setColorAt(0.2, Qt.green) - linear_gradient.setColorAt(1.0, Qt.black) + linear_gradient.setColorAt(0.0, Qt.GlobalColor.white) + linear_gradient.setColorAt(0.2, Qt.GlobalColor.green) + linear_gradient.setColorAt(1.0, Qt.GlobalColor.black) self._render_area.set_brush(QBrush(linear_gradient)) - elif style == Qt.RadialGradientPattern: + elif style == Qt.BrushStyle.RadialGradientPattern: radial_gradient = QRadialGradient(50, 50, 50, 70, 70) - radial_gradient.setColorAt(0.0, Qt.white) - radial_gradient.setColorAt(0.2, Qt.green) - radial_gradient.setColorAt(1.0, Qt.black) + radial_gradient.setColorAt(0.0, Qt.GlobalColor.white) + radial_gradient.setColorAt(0.2, Qt.GlobalColor.green) + radial_gradient.setColorAt(1.0, Qt.GlobalColor.black) self._render_area.set_brush(QBrush(radial_gradient)) - elif style == Qt.ConicalGradientPattern: + elif style == Qt.BrushStyle.ConicalGradientPattern: conical_gradient = QConicalGradient(50, 50, 150) - conical_gradient.setColorAt(0.0, Qt.white) - conical_gradient.setColorAt(0.2, Qt.green) - conical_gradient.setColorAt(1.0, Qt.black) + conical_gradient.setColorAt(0.0, Qt.GlobalColor.white) + conical_gradient.setColorAt(0.2, Qt.GlobalColor.green) + conical_gradient.setColorAt(1.0, Qt.GlobalColor.black) self._render_area.set_brush(QBrush(conical_gradient)) - elif style == Qt.TexturePattern: + elif style == Qt.BrushStyle.TexturePattern: self._render_area.set_brush(QBrush(QPixmap(':/images/brick.png'))) else: - self._render_area.set_brush(QBrush(Qt.green, style)) + self._render_area.set_brush(QBrush(Qt.GlobalColor.green, style)) if __name__ == '__main__': diff --git a/examples/widgets/painting/concentriccircles/concentriccircles.py b/examples/widgets/painting/concentriccircles/concentriccircles.py index df415fb0f..4eef4df77 100644 --- a/examples/widgets/painting/concentriccircles/concentriccircles.py +++ b/examples/widgets/painting/concentriccircles/concentriccircles.py @@ -20,8 +20,8 @@ class CircleWidget(QWidget): self.antialiased = False self._frame_no = 0 - self.setBackgroundRole(QPalette.Base) - self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + self.setBackgroundRole(QPalette.ColorRole.Base) + self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) def set_float_based(self, floatBased): self._float_based = floatBased @@ -94,9 +94,9 @@ class Window(QWidget): def create_label(self, text): label = QLabel(text) - label.setAlignment(Qt.AlignCenter) + label.setAlignment(Qt.AlignmentFlag.AlignCenter) label.setMargin(2) - label.setFrameStyle(QFrame.Box | QFrame.Sunken) + label.setFrameStyle(QFrame.Shape.Box | QFrame.Shadow.Sunken) return label diff --git a/examples/widgets/painting/painter/painter.py b/examples/widgets/painting/painter/painter.py index b1d280c3b..4b009b30d 100644 --- a/examples/widgets/painting/painter/painter.py +++ b/examples/widgets/painting/painter/painter.py @@ -37,14 +37,14 @@ class PainterWidget(QWidget): self.setFixedSize(680, 480) self.pixmap = QPixmap(self.size()) - self.pixmap.fill(Qt.white) + self.pixmap.fill(Qt.GlobalColor.white) self.previous_pos = None self.painter = QPainter() self.pen = QPen() self.pen.setWidth(10) - self.pen.setCapStyle(Qt.RoundCap) - self.pen.setJoinStyle(Qt.RoundJoin) + self.pen.setCapStyle(Qt.PenCapStyle.RoundCap) + self.pen.setJoinStyle(Qt.PenJoinStyle.RoundJoin) def paintEvent(self, event: QPaintEvent): """Override method from QWidget @@ -98,12 +98,12 @@ class PainterWidget(QWidget): def load(self, filename: str): """ load pixmap from filename """ self.pixmap.load(filename) - self.pixmap = self.pixmap.scaled(self.size(), Qt.KeepAspectRatio) + self.pixmap = self.pixmap.scaled(self.size(), Qt.AspectRatioMode.KeepAspectRatio) self.update() def clear(self): """ Clear the pixmap """ - self.pixmap.fill(Qt.white) + self.pixmap.fill(Qt.GlobalColor.white) self.update() @@ -115,19 +115,19 @@ class MainWindow(QMainWindow): self.painter_widget = PainterWidget() self.bar = self.addToolBar("Menu") - self.bar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) + self.bar.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) self._save_action = self.bar.addAction( - qApp.style().standardIcon(QStyle.SP_DialogSaveButton), # noqa: F821 + qApp.style().standardIcon(QStyle.StandardPixmap.SP_DialogSaveButton), # noqa: F821 "Save", self.on_save ) - self._save_action.setShortcut(QKeySequence.Save) + self._save_action.setShortcut(QKeySequence.StandardKey.Save) self._open_action = self.bar.addAction( - qApp.style().standardIcon(QStyle.SP_DialogOpenButton), # noqa: F821 + qApp.style().standardIcon(QStyle.StandardPixmap.SP_DialogOpenButton), # noqa: F821 "Open", self.on_open ) - self._open_action.setShortcut(QKeySequence.Open) + self._open_action.setShortcut(QKeySequence.StandardKey.Open) self.bar.addAction( - qApp.style().standardIcon(QStyle.SP_DialogResetButton), # noqa: F821 + qApp.style().standardIcon(QStyle.StandardPixmap.SP_DialogResetButton), # noqa: F821 "Clear", self.painter_widget.clear, ) @@ -139,7 +139,7 @@ class MainWindow(QMainWindow): self.setCentralWidget(self.painter_widget) - self.color = Qt.black + self.color = Qt.GlobalColor.black self.set_color(self.color) self.mime_type_filters = ["image/png", "image/jpeg"] @@ -149,14 +149,14 @@ class MainWindow(QMainWindow): dialog = QFileDialog(self, "Save File") dialog.setMimeTypeFilters(self.mime_type_filters) - dialog.setFileMode(QFileDialog.AnyFile) - dialog.setAcceptMode(QFileDialog.AcceptSave) + dialog.setFileMode(QFileDialog.FileMode.AnyFile) + dialog.setAcceptMode(QFileDialog.AcceptMode.AcceptSave) dialog.setDefaultSuffix("png") dialog.setDirectory( - QStandardPaths.writableLocation(QStandardPaths.PicturesLocation) + QStandardPaths.writableLocation(QStandardPaths.StandardLocation.PicturesLocation) ) - if dialog.exec() == QFileDialog.Accepted: + if dialog.exec() == QFileDialog.DialogCode.Accepted: if dialog.selectedFiles(): self.painter_widget.save(dialog.selectedFiles()[0]) @@ -165,14 +165,14 @@ class MainWindow(QMainWindow): dialog = QFileDialog(self, "Save File") dialog.setMimeTypeFilters(self.mime_type_filters) - dialog.setFileMode(QFileDialog.ExistingFile) - dialog.setAcceptMode(QFileDialog.AcceptOpen) + dialog.setFileMode(QFileDialog.FileMode.ExistingFile) + dialog.setAcceptMode(QFileDialog.AcceptMode.AcceptOpen) dialog.setDefaultSuffix("png") dialog.setDirectory( - QStandardPaths.writableLocation(QStandardPaths.PicturesLocation) + QStandardPaths.writableLocation(QStandardPaths.StandardLocation.PicturesLocation) ) - if dialog.exec() == QFileDialog.Accepted: + if dialog.exec() == QFileDialog.DialogCode.Accepted: if dialog.selectedFiles(): self.painter_widget.load(dialog.selectedFiles()[0]) @@ -184,7 +184,7 @@ class MainWindow(QMainWindow): if color: self.set_color(color) - def set_color(self, color: QColor = Qt.black): + def set_color(self, color: QColor = Qt.GlobalColor.black): self.color = color # Create color icon diff --git a/examples/widgets/painting/plot/plot.py b/examples/widgets/painting/plot/plot.py index d437309d0..5e564511f 100644 --- a/examples/widgets/painting/plot/plot.py +++ b/examples/widgets/painting/plot/plot.py @@ -53,7 +53,7 @@ class PlotWidget(QWidget): def paintEvent(self, event): with QPainter(self) as painter: rect = QRect(QPoint(0, 0), self.size()) - painter.fillRect(rect, Qt.white) + painter.fillRect(rect, Qt.GlobalColor.white) painter.translate(-self._points[0].x(), 0) painter.drawPolyline(self._points) diff --git a/examples/widgets/richtext/orderform/orderform.py b/examples/widgets/richtext/orderform/orderform.py index 66a9c2d02..6e0818e1c 100644 --- a/examples/widgets/richtext/orderform/orderform.py +++ b/examples/widgets/richtext/orderform/orderform.py @@ -46,7 +46,7 @@ class MainWindow(QMainWindow): self.letters.setCurrentIndex(tab_index) cursor = editor.textCursor() - cursor.movePosition(QTextCursor.Start) + cursor.movePosition(QTextCursor.MoveOperation.Start) top_frame = cursor.currentFrame() top_frame_format = top_frame.frameFormat() top_frame_format.setPadding(16) @@ -54,13 +54,13 @@ class MainWindow(QMainWindow): text_format = QTextCharFormat() bold_format = QTextCharFormat() - bold_format.setFontWeight(QFont.Bold) + bold_format.setFontWeight(QFont.Weight.Bold) reference_frame_format = QTextFrameFormat() reference_frame_format.setBorder(1) reference_frame_format.setPadding(8) - reference_frame_format.setPosition(QTextFrameFormat.FloatRight) - reference_frame_format.setWidth(QTextLength(QTextLength.PercentageLength, 40)) + reference_frame_format.setPosition(QTextFrameFormat.Position.FloatRight) + reference_frame_format.setWidth(QTextLength(QTextLength.Type.PercentageLength, 40)) cursor.insertFrame(reference_frame_format) cursor.insertText("A company", bold_format) @@ -87,7 +87,7 @@ class MainWindow(QMainWindow): cursor.insertBlock() body_frame_format = QTextFrameFormat() - body_frame_format.setWidth(QTextLength(QTextLength.PercentageLength, 100)) + body_frame_format.setWidth(QTextLength(QTextLength.Type.PercentageLength, 100)) cursor.insertFrame(body_frame_format) cursor.insertText("I would like to place an order for the following items:", text_format) @@ -95,7 +95,7 @@ class MainWindow(QMainWindow): cursor.insertBlock() order_table_format = QTextTableFormat() - order_table_format.setAlignment(Qt.AlignHCenter) + order_table_format.setAlignment(Qt.AlignmentFlag.AlignHCenter) order_table = cursor.insertTable(1, 2, order_table_format) order_frame_format = cursor.currentFrame().frameFormat() @@ -189,7 +189,7 @@ class DetailsDialog(QDialog): name_label = QLabel("Name:") address_label = QLabel("Address:") - address_label.setAlignment(Qt.AlignLeft | Qt.AlignTop) + address_label.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop) self._name_edit = QLineEdit() self._address_edit = QTextEdit() @@ -197,7 +197,8 @@ class DetailsDialog(QDialog): self.setup_items_table() - button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok + | QDialogButtonBox.StandardButton.Cancel) button_box.accepted.connect(self.verify) button_box.rejected.connect(self.reject) @@ -218,7 +219,7 @@ class DetailsDialog(QDialog): for row, item in enumerate(self.items): name = QTableWidgetItem(item) - name.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) + name.setFlags(Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsSelectable) self._items_table.setItem(row, 0, name) quantity = QTableWidgetItem('1') self._items_table.setItem(row, 1, quantity) diff --git a/examples/widgets/richtext/textedit/textedit.py b/examples/widgets/richtext/textedit/textedit.py index 428a5eae3..8cd330a72 100644 --- a/examples/widgets/richtext/textedit/textedit.py +++ b/examples/widgets/richtext/textedit/textedit.py @@ -49,7 +49,7 @@ class TextEdit(QMainWindow): self._text_edit.cursorPositionChanged.connect(self.cursor_position_changed) self.setCentralWidget(self._text_edit) - self.setToolButtonStyle(Qt.ToolButtonFollowStyle) + self.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonFollowStyle) self.setup_file_actions() self.setup_edit_actions() self.setup_text_actions() @@ -59,7 +59,7 @@ class TextEdit(QMainWindow): help_menu.addAction("About &Qt", qApp.aboutQt) # noqa: F821 text_font = QFont("Helvetica") - text_font.setStyleHint(QFont.SansSerif) + text_font.setStyleHint(QFont.StyleHint.SansSerif) self._text_edit.setFont(text_font) self.font_changed(self._text_edit.font()) self.color_changed(self._text_edit.textColor()) @@ -88,8 +88,8 @@ class TextEdit(QMainWindow): # Use dark text on light background on macOS, also in dark mode. if sys.platform == 'darwin': pal = self._text_edit.palette() - pal.setColor(QPalette.Base, QColor(Qt.white)) - pal.setColor(QPalette.Text, QColor(Qt.black)) + pal.setColor(QPalette.Base, QColor(Qt.GlobalColor.white)) + pal.setColor(QPalette.Text, QColor(Qt.GlobalColor.black)) self._text_edit.setPalette(pal) def closeEvent(self, e): @@ -106,13 +106,13 @@ class TextEdit(QMainWindow): QIcon(RSRC_PATH + "/filenew.png")) a = menu.addAction(icon, "&New", self.file_new) tb.addAction(a) - a.setPriority(QAction.LowPriority) - a.setShortcut(QKeySequence.New) + a.setPriority(QAction.Priority.LowPriority) + a.setShortcut(QKeySequence.StandardKey.New) icon = QIcon.fromTheme(QIcon.ThemeIcon.DocumentOpen, QIcon(RSRC_PATH + "/fileopen.png")) a = menu.addAction(icon, "&Open...", self.file_open) - a.setShortcut(QKeySequence.Open) + a.setShortcut(QKeySequence.StandardKey.Open) tb.addAction(a) menu.addSeparator() @@ -120,19 +120,19 @@ class TextEdit(QMainWindow): icon = QIcon.fromTheme(QIcon.ThemeIcon.DocumentSave, QIcon(RSRC_PATH + "/filesave.png")) self._action_save = menu.addAction(icon, "&Save", self.file_save) - self._action_save.setShortcut(QKeySequence.Save) + self._action_save.setShortcut(QKeySequence.StandardKey.Save) self._action_save.setEnabled(False) tb.addAction(self._action_save) a = menu.addAction("Save &As...", self.file_save_as) - a.setPriority(QAction.LowPriority) + a.setPriority(QAction.Priority.LowPriority) menu.addSeparator() icon = QIcon.fromTheme(QIcon.ThemeIcon.DocumentPrint, QIcon(RSRC_PATH + "/fileprint.png")) a = menu.addAction(icon, "&Print...", self.file_print) - a.setPriority(QAction.LowPriority) - a.setShortcut(QKeySequence.Print) + a.setPriority(QAction.Priority.LowPriority) + a.setShortcut(QKeySequence.StandardKey.Print) tb.addAction(a) icon = QIcon.fromTheme("fileprint", QIcon(RSRC_PATH + "/fileprint.png")) @@ -140,14 +140,14 @@ class TextEdit(QMainWindow): icon = QIcon.fromTheme("exportpdf", QIcon(RSRC_PATH + "/exportpdf.png")) a = menu.addAction(icon, "&Export PDF...", self.file_print_pdf) - a.setPriority(QAction.LowPriority) - a.setShortcut(Qt.CTRL | Qt.Key_D) + a.setPriority(QAction.Priority.LowPriority) + a.setShortcut(Qt.Modifier.CTRL | Qt.Key.Key_D) tb.addAction(a) menu.addSeparator() a = menu.addAction("&Quit", self.close) - a.setShortcut(Qt.CTRL | Qt.Key_Q) + a.setShortcut(Qt.Modifier.CTRL | Qt.Key.Key_Q) def setup_edit_actions(self): tb = self.addToolBar("Edit self.actions") @@ -156,36 +156,36 @@ class TextEdit(QMainWindow): icon = QIcon.fromTheme(QIcon.ThemeIcon.EditUndo, QIcon(RSRC_PATH + "/editundo.png")) self._action_undo = menu.addAction(icon, "&Undo", self._text_edit.undo) - self._action_undo.setShortcut(QKeySequence.Undo) + self._action_undo.setShortcut(QKeySequence.StandardKey.Undo) tb.addAction(self._action_undo) icon = QIcon.fromTheme(QIcon.ThemeIcon.EditRedo, QIcon(RSRC_PATH + "/editredo.png")) self._action_redo = menu.addAction(icon, "&Redo", self._text_edit.redo) - self._action_redo.setPriority(QAction.LowPriority) - self._action_redo.setShortcut(QKeySequence.Redo) + self._action_redo.setPriority(QAction.Priority.LowPriority) + self._action_redo.setShortcut(QKeySequence.StandardKey.Redo) tb.addAction(self._action_redo) menu.addSeparator() icon = QIcon.fromTheme(QIcon.ThemeIcon.EditCut, QIcon(RSRC_PATH + "/editcut.png")) self._action_cut = menu.addAction(icon, "Cu&t", self._text_edit.cut) - self._action_cut.setPriority(QAction.LowPriority) - self._action_cut.setShortcut(QKeySequence.Cut) + self._action_cut.setPriority(QAction.Priority.LowPriority) + self._action_cut.setShortcut(QKeySequence.StandardKey.Cut) tb.addAction(self._action_cut) icon = QIcon.fromTheme(QIcon.ThemeIcon.EditCopy, QIcon(RSRC_PATH + "/editcopy.png")) self._action_copy = menu.addAction(icon, "&Copy", self._text_edit.copy) - self._action_copy.setPriority(QAction.LowPriority) - self._action_copy.setShortcut(QKeySequence.Copy) + self._action_copy.setPriority(QAction.Priority.LowPriority) + self._action_copy.setShortcut(QKeySequence.StandardKey.Copy) tb.addAction(self._action_copy) icon = QIcon.fromTheme(QIcon.ThemeIcon.EditPaste, QIcon(RSRC_PATH + "/editpaste.png")) self._action_paste = menu.addAction(icon, "&Paste", self._text_edit.paste) - self._action_paste.setPriority(QAction.LowPriority) - self._action_paste.setShortcut(QKeySequence.Paste) + self._action_paste.setPriority(QAction.Priority.LowPriority) + self._action_paste.setShortcut(QKeySequence.StandardKey.Paste) tb.addAction(self._action_paste) md = QGuiApplication.clipboard().mimeData() @@ -199,8 +199,8 @@ class TextEdit(QMainWindow): icon = QIcon.fromTheme(QIcon.ThemeIcon.FormatTextBold, QIcon(RSRC_PATH + "/textbold.png")) self._action_text_bold = menu.addAction(icon, "&Bold", self.text_bold) - self._action_text_bold.setShortcut(Qt.CTRL | Qt.Key_B) - self._action_text_bold.setPriority(QAction.LowPriority) + self._action_text_bold.setShortcut(Qt.Modifier.CTRL | Qt.Key.Key_B) + self._action_text_bold.setPriority(QAction.Priority.LowPriority) bold = QFont() bold.setBold(True) self._action_text_bold.setFont(bold) @@ -210,8 +210,8 @@ class TextEdit(QMainWindow): icon = QIcon.fromTheme(QIcon.ThemeIcon.FormatTextItalic, QIcon(RSRC_PATH + "/textitalic.png")) self._action_text_italic = menu.addAction(icon, "&Italic", self.text_italic) - self._action_text_italic.setPriority(QAction.LowPriority) - self._action_text_italic.setShortcut(Qt.CTRL | Qt.Key_I) + self._action_text_italic.setPriority(QAction.Priority.LowPriority) + self._action_text_italic.setShortcut(Qt.Modifier.CTRL | Qt.Key.Key_I) italic = QFont() italic.setItalic(True) self._action_text_italic.setFont(italic) @@ -222,8 +222,8 @@ class TextEdit(QMainWindow): QIcon(RSRC_PATH + "/textunder.png")) self._action_text_underline = menu.addAction(icon, "&Underline", self.text_underline) - self._action_text_underline.setShortcut(Qt.CTRL | Qt.Key_U) - self._action_text_underline.setPriority(QAction.LowPriority) + self._action_text_underline.setShortcut(Qt.Modifier.CTRL | Qt.Key.Key_U) + self._action_text_underline.setPriority(QAction.Priority.LowPriority) underline = QFont() underline.setUnderline(True) self._action_text_underline.setFont(underline) @@ -235,38 +235,38 @@ class TextEdit(QMainWindow): icon = QIcon.fromTheme(QIcon.ThemeIcon.FormatJustifyLeft, QIcon(RSRC_PATH + "/textleft.png")) self._action_align_left = QAction(icon, "&Left", self) - self._action_align_left.setShortcut(Qt.CTRL | Qt.Key_L) + self._action_align_left.setShortcut(Qt.Modifier.CTRL | Qt.Key.Key_L) self._action_align_left.setCheckable(True) - self._action_align_left.setPriority(QAction.LowPriority) + self._action_align_left.setPriority(QAction.Priority.LowPriority) icon = QIcon.fromTheme(QIcon.ThemeIcon.FormatJustifyCenter, QIcon(RSRC_PATH + "/textcenter.png")) self._action_align_center = QAction(icon, "C&enter", self) - self._action_align_center.setShortcut(Qt.CTRL | Qt.Key_E) + self._action_align_center.setShortcut(Qt.Modifier.CTRL | Qt.Key.Key_E) self._action_align_center.setCheckable(True) - self._action_align_center.setPriority(QAction.LowPriority) + self._action_align_center.setPriority(QAction.Priority.LowPriority) icon = QIcon.fromTheme(QIcon.ThemeIcon.FormatJustifyRight, QIcon(RSRC_PATH + "/textright.png")) self._action_align_right = QAction(icon, "&Right", self) - self._action_align_right.setShortcut(Qt.CTRL | Qt.Key_R) + self._action_align_right.setShortcut(Qt.Modifier.CTRL | Qt.Key.Key_R) self._action_align_right.setCheckable(True) - self._action_align_right.setPriority(QAction.LowPriority) + self._action_align_right.setPriority(QAction.Priority.LowPriority) icon = QIcon.fromTheme(QIcon.ThemeIcon.FormatJustifyFill, QIcon(RSRC_PATH + "/textjustify.png")) self._action_align_justify = QAction(icon, "&Justify", self) - self._action_align_justify.setShortcut(Qt.CTRL | Qt.Key_J) + self._action_align_justify.setShortcut(Qt.Modifier.CTRL | Qt.Key.Key_J) self._action_align_justify.setCheckable(True) - self._action_align_justify.setPriority(QAction.LowPriority) + self._action_align_justify.setPriority(QAction.Priority.LowPriority) icon = QIcon.fromTheme(QIcon.ThemeIcon.FormatIndentMore, QIcon(RSRC_PATH + "/format-indent-more.png")) self._action_indent_more = menu.addAction(icon, "&Indent", self.indent) - self._action_indent_more.setShortcut(Qt.CTRL | Qt.Key_BracketRight) - self._action_indent_more.setPriority(QAction.LowPriority) + self._action_indent_more.setShortcut(Qt.Modifier.CTRL | Qt.Key.Key_BracketRight) + self._action_indent_more.setPriority(QAction.Priority.LowPriority) icon = QIcon.fromTheme(QIcon.ThemeIcon.FormatIndentLess, QIcon(RSRC_PATH + "/format-indent-less.png")) self._action_indent_less = menu.addAction(icon, "&Unindent", self.unindent) - self._action_indent_less.setShortcut(Qt.CTRL | Qt.Key_BracketLeft) - self._action_indent_less.setPriority(QAction.LowPriority) + self._action_indent_less.setShortcut(Qt.Modifier.CTRL | Qt.Key.Key_BracketLeft) + self._action_indent_less.setPriority(QAction.Priority.LowPriority) # Make sure the alignLeft is always left of the alignRight align_group = QActionGroup(self) @@ -292,7 +292,7 @@ class TextEdit(QMainWindow): menu.addSeparator() pix = QPixmap(16, 16) - pix.fill(Qt.black) + pix.fill(Qt.GlobalColor.black) self._action_text_color = menu.addAction(pix, "&Color...", self.text_color) tb.addAction(self._action_text_color) @@ -307,14 +307,14 @@ class TextEdit(QMainWindow): QIcon(RSRC_PATH + "/checkbox-checked.png")) self._action_toggle_check_state = menu.addAction(icon, "Chec&ked") self._action_toggle_check_state.toggled.connect(self.set_checked) - self._action_toggle_check_state.setShortcut(Qt.CTRL | Qt.Key_K) + self._action_toggle_check_state.setShortcut(Qt.Modifier.CTRL | Qt.Key.Key_K) self._action_toggle_check_state.setCheckable(True) - self._action_toggle_check_state.setPriority(QAction.LowPriority) + self._action_toggle_check_state.setPriority(QAction.Priority.LowPriority) tb.addAction(self._action_toggle_check_state) tb = self.addToolBar("Format self.actions") - tb.setAllowedAreas(Qt.TopToolBarArea | Qt.BottomToolBarArea) - self.addToolBarBreak(Qt.TopToolBarArea) + tb.setAllowedAreas(Qt.ToolBarArea.TopToolBarArea | Qt.ToolBarArea.BottomToolBarArea) + self.addToolBarBreak(Qt.ToolBarArea.TopToolBarArea) self.addToolBar(tb) self._combo_style = QComboBox(tb) @@ -344,7 +344,7 @@ class TextEdit(QMainWindow): if not QFile.exists(f): return False file = QFile(f) - if not file.open(QFile.ReadOnly): + if not file.open(QFile.OpenModeFlag.ReadOnly): return False data = file.readAll() @@ -353,7 +353,7 @@ class TextEdit(QMainWindow): text = data.data().decode('utf8') if mime_type_name == "text/html": file_url = QUrl(f) if f[0] == ':' else QUrl.fromLocalFile(f) - options = QUrl.FormattingOptions(QUrl.RemoveFilename) + options = QUrl.FormattingOptions(QUrl.UrlFormattingOption.RemoveFilename) self._text_edit.document().setBaseUrl(file_url.adjusted(options)) self._text_edit.setHtml(text) elif mime_type_name == "text/markdown": @@ -586,7 +586,7 @@ class TextEdit(QMainWindow): @Slot() def underline_color(self): - col = QColorDialog.getColor(Qt.black, self) + col = QColorDialog.getColor(Qt.GlobalColor.black, self) if not col.isValid(): return fmt = QTextCharFormat() @@ -597,13 +597,15 @@ class TextEdit(QMainWindow): @Slot(QAction) def text_align(self, a): if a == self._action_align_left: - self._text_edit.setAlignment(Qt.AlignLeft | Qt.AlignAbsolute) + self._text_edit.setAlignment(Qt.AlignmentFlag.AlignLeft + | Qt.AlignmentFlag.AlignAbsolute) elif a == self._action_align_center: - self._text_edit.setAlignment(Qt.AlignHCenter) + self._text_edit.setAlignment(Qt.AlignmentFlag.AlignHCenter) elif a == self._action_align_right: - self._text_edit.setAlignment(Qt.AlignRight | Qt.AlignAbsolute) + self._text_edit.setAlignment(Qt.AlignmentFlag.AlignRight + | Qt.AlignmentFlag.AlignAbsolute) elif a == self._action_align_justify: - self._text_edit.setAlignment(Qt.AlignJustify) + self._text_edit.setAlignment(Qt.AlignmentFlag.AlignJustify) @Slot(bool) def set_checked(self, checked): @@ -712,11 +714,11 @@ class TextEdit(QMainWindow): self._action_text_color.setIcon(pix) def alignment_changed(self, a): - if a & Qt.AlignLeft: + if a & Qt.AlignmentFlag.AlignLeft: self._action_align_left.setChecked(True) - elif a & Qt.AlignHCenter: + elif a & Qt.AlignmentFlag.AlignHCenter: self._action_align_center.setChecked(True) - elif a & Qt.AlignRight: + elif a & Qt.AlignmentFlag.AlignRight: self._action_align_right.setChecked(True) - elif a & Qt.AlignJustify: + elif a & Qt.AlignmentFlag.AlignJustify: self._action_align_justify.setChecked(True) diff --git a/examples/widgets/tools/regularexpression/regularexpressiondialog.py b/examples/widgets/tools/regularexpression/regularexpressiondialog.py index bbaa2f452..cdca1a833 100644 --- a/examples/widgets/tools/regularexpression/regularexpressiondialog.py +++ b/examples/widgets/tools/regularexpression/regularexpressiondialog.py @@ -56,13 +56,13 @@ def codeToPattern(code: str) -> str: def createHorizontalSeparator() -> QFrame: result = QFrame() - result.setFrameStyle(QFrame.HLine | QFrame.Sunken) + result.setFrameStyle(QFrame.Shape.HLine | QFrame.Shadow.Sunken) return result def createVerticalSeparator() -> QFrame: result = QFrame() - result.setFrameStyle(QFrame.VLine | QFrame.Sunken) + result.setFrameStyle(QFrame.Shape.VLine | QFrame.Shadow.Sunken) return result @@ -102,7 +102,7 @@ class PatternLineEdit(QLineEdit): def contextMenuEvent(self, event: QContextMenuEvent) -> None: menu = self.createStandardContextMenu() - menu.setAttribute(Qt.WA_DeleteOnClose) + menu.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose) menu.addSeparator() self.escapeSelectionAction.setEnabled(self.hasSelectedText()) menu.addAction(self.escapeSelectionAction) @@ -118,8 +118,8 @@ class DisplayLineEdit(QLineEdit): self.setReadOnly(True) self.disablePalette: QPalette = self.palette() self.disablePalette.setBrush( - QPalette.Base, - self.disablePalette.brush(QPalette.Disabled, QPalette.Base), + QPalette.ColorRole.Base, + self.disablePalette.brush(QPalette.ColorGroup.Disabled, QPalette.ColorRole.Base), ) self.setPalette(self.disablePalette) @@ -129,7 +129,7 @@ class DisplayLineEdit(QLineEdit): self.copyAction.triggered.connect( lambda: QGuiApplication.clipboard().setText(self.text()) ) - self.addAction(self.copyAction, QLineEdit.TrailingPosition) + self.addAction(self.copyAction, QLineEdit.ActionPosition.TrailingPosition) class RegularExpressionDialog(QDialog): @@ -167,7 +167,7 @@ class RegularExpressionDialog(QDialog): def setTextColor(self, widget: QWidget, color: QColor): self.palette: QPalette = widget.palette() - self.palette.setColor(QPalette.Text, color) + self.palette.setColor(QPalette.ColorRole.Text, color) widget.setPalette(self.palette) @Slot() @@ -183,7 +183,7 @@ class RegularExpressionDialog(QDialog): self.setTextColor( self.patternLineEdit, - self.subjectTextEdit.palette().color(QPalette.Text), + self.subjectTextEdit.palette().color(QPalette.ColorRole.Text), ) self.matchDetailsTreeWidget.clear() self.namedGroupsTreeWidget.clear() @@ -214,28 +214,28 @@ class RegularExpressionDialog(QDialog): matchType: QRegularExpression.MatchType = QRegularExpression.MatchType( self.matchTypeComboBox.currentData() ) - patternOptions = QRegularExpression.NoPatternOption - matchOptions = QRegularExpression.NoMatchOption + patternOptions = QRegularExpression.PatternOption.NoPatternOption + matchOptions = QRegularExpression.MatchOption.NoMatchOption if self.anchoredMatchOptionCheckBox.isChecked(): - matchOptions |= QRegularExpression.AnchorAtOffsetMatchOption + matchOptions |= QRegularExpression.MatchOption.AnchorAtOffsetMatchOption if self.dontCheckSubjectStringMatchOptionCheckBox.isChecked(): - matchOptions |= QRegularExpression.DontCheckSubjectStringMatchOption + matchOptions |= QRegularExpression.MatchOption.DontCheckSubjectStringMatchOption if self.caseInsensitiveOptionCheckBox.isChecked(): - patternOptions |= QRegularExpression.CaseInsensitiveOption + patternOptions |= QRegularExpression.PatternOption.CaseInsensitiveOption if self.dotMatchesEverythingOptionCheckBox.isChecked(): - patternOptions |= QRegularExpression.DotMatchesEverythingOption + patternOptions |= QRegularExpression.PatternOption.DotMatchesEverythingOption if self.multilineOptionCheckBox.isChecked(): - patternOptions |= QRegularExpression.MultilineOption + patternOptions |= QRegularExpression.PatternOption.MultilineOption if self.extendedPatternSyntaxOptionCheckBox.isChecked(): - patternOptions |= QRegularExpression.ExtendedPatternSyntaxOption + patternOptions |= QRegularExpression.PatternOption.ExtendedPatternSyntaxOption if self.invertedGreedinessOptionCheckBox.isChecked(): - patternOptions |= QRegularExpression.InvertedGreedinessOption + patternOptions |= QRegularExpression.PatternOption.InvertedGreedinessOption if self.dontCaptureOptionCheckBox.isChecked(): - patternOptions |= QRegularExpression.DontCaptureOption + patternOptions |= QRegularExpression.PatternOption.DontCaptureOption if self.useUnicodePropertiesOptionCheckBox.isChecked(): - patternOptions |= QRegularExpression.UseUnicodePropertiesOption + patternOptions |= QRegularExpression.PatternOption.UseUnicodePropertiesOption self.regularExpression.setPatternOptions(patternOptions) @@ -302,7 +302,7 @@ class RegularExpressionDialog(QDialog): self.horizontalLayout.addWidget(createVerticalSeparator()) self.horizontalLayout.addWidget(self.setupInfoUi()) - self._font = QFontDatabase.systemFont(QFontDatabase.FixedFont) + self._font = QFontDatabase.systemFont(QFontDatabase.SystemFont.FixedFont) self.patternLineEdit.setFont(self._font) self.rawStringLiteralLineEdit.setFont(self._font) self.escapedPatternLineEdit.setFont(self._font) @@ -314,7 +314,7 @@ class RegularExpressionDialog(QDialog): container = QWidget() form_layout = QFormLayout(container) - form_layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) + form_layout.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.AllNonFixedFieldsGrow) form_layout.setContentsMargins(QMargins()) form_layout.addRow(QLabel("<h3>Options</h3>")) @@ -351,15 +351,15 @@ class RegularExpressionDialog(QDialog): form_layout.addRow("Match &offset:", self.offsetSpinBox) self.matchTypeComboBox = QComboBox() - self.matchTypeComboBox.addItem("Normal", QRegularExpression.NormalMatch) + self.matchTypeComboBox.addItem("Normal", QRegularExpression.MatchType.NormalMatch) self.matchTypeComboBox.addItem( "Partial prefer complete", - QRegularExpression.PartialPreferCompleteMatch, + QRegularExpression.MatchType.PartialPreferCompleteMatch, ) self.matchTypeComboBox.addItem( - "Partial prefer first", QRegularExpression.PartialPreferFirstMatch + "Partial prefer first", QRegularExpression.MatchType.PartialPreferFirstMatch ) - self.matchTypeComboBox.addItem("No match", QRegularExpression.NoMatch) + self.matchTypeComboBox.addItem("No match", QRegularExpression.MatchType.NoMatch) form_layout.addRow("Match &type:", self.matchTypeComboBox) self.dontCheckSubjectStringMatchOptionCheckBox = QCheckBox( @@ -382,7 +382,7 @@ class RegularExpressionDialog(QDialog): container = QWidget() form_layout = QFormLayout(container) - form_layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) + form_layout.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.AllNonFixedFieldsGrow) form_layout.setContentsMargins(QMargins()) self.matchInfoLabel = QLabel("<h3>Match information</h3>") @@ -393,7 +393,7 @@ class RegularExpressionDialog(QDialog): self.matchDetailsTreeWidget.setHeaderLabels( ["Match index", "Group index", "Captured string"] ) - self.matchDetailsTreeWidget.setSizeAdjustPolicy(QTreeWidget.AdjustToContents) + self.matchDetailsTreeWidget.setSizeAdjustPolicy(QTreeWidget.SizeAdjustPolicy.AdjustToContents) # noqa: E501 form_layout.addRow("Match details:", self.matchDetailsTreeWidget) form_layout.addRow(createHorizontalSeparator()) @@ -407,7 +407,7 @@ class RegularExpressionDialog(QDialog): self.namedGroupsTreeWidget = QTreeWidget() self.namedGroupsTreeWidget.setHeaderLabels(["Index", "Named group"]) - self.namedGroupsTreeWidget.setSizeAdjustPolicy(QTreeWidget.AdjustToContents) + self.namedGroupsTreeWidget.setSizeAdjustPolicy(QTreeWidget.SizeAdjustPolicy.AdjustToContents) # noqa: E501 self.namedGroupsTreeWidget.setRootIsDecorated(False) form_layout.addRow("Named groups:", self.namedGroupsTreeWidget) @@ -416,7 +416,7 @@ class RegularExpressionDialog(QDialog): def setupTextUi(self): container = QWidget() form_layout = QFormLayout(container) - form_layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) + form_layout.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.AllNonFixedFieldsGrow) form_layout.setContentsMargins(QMargins()) self.regexpAndSubjectLabel = QLabel( diff --git a/examples/widgets/tutorials/cannon/t10.py b/examples/widgets/tutorials/cannon/t10.py index d516104bc..0498eb23e 100644 --- a/examples/widgets/tutorials/cannon/t10.py +++ b/examples/widgets/tutorials/cannon/t10.py @@ -93,8 +93,8 @@ class CannonField(QWidget): def paintEvent(self, event): with QPainter(self) as painter: - painter.setPen(Qt.NoPen) - painter.setBrush(Qt.blue) + painter.setPen(Qt.PenStyle.NoPen) + painter.setBrush(Qt.GlobalColor.blue) painter.translate(0, self.height()) painter.drawPie(QRect(-35, -35, 70, 70), 0, 90 * 16) @@ -112,7 +112,7 @@ class MyWidget(QWidget): super().__init__(parent) quit = QPushButton("&Quit") - quit.setFont(QFont("Times", 18, QFont.Bold)) + quit.setFont(QFont("Times", 18, QFont.Weight.Bold)) quit.clicked.connect(qApp.quit) # noqa: F821 diff --git a/examples/widgets/tutorials/cannon/t11.py b/examples/widgets/tutorials/cannon/t11.py index 71d6e3cd3..00ac2fc26 100644 --- a/examples/widgets/tutorials/cannon/t11.py +++ b/examples/widgets/tutorials/cannon/t11.py @@ -128,15 +128,15 @@ class CannonField(QWidget): self.paint_shot(painter) def paint_shot(self, painter): - painter.setPen(Qt.NoPen) - painter.setBrush(Qt.black) + painter.setPen(Qt.PenStyle.NoPen) + painter.setBrush(Qt.GlobalColor.black) painter.drawRect(self.shot_rect()) barrel_rect = QRect(33, -4, 15, 8) def paint_cannon(self, painter): - painter.setPen(Qt.NoPen) - painter.setBrush(Qt.blue) + painter.setPen(Qt.PenStyle.NoPen) + painter.setBrush(Qt.GlobalColor.blue) painter.save() painter.translate(0, self.height()) @@ -174,7 +174,7 @@ class MyWidget(QWidget): super().__init__(parent) quit = QPushButton("&Quit") - quit.setFont(QFont("Times", 18, QFont.Bold)) + quit.setFont(QFont("Times", 18, QFont.Weight.Bold)) quit.clicked.connect(qApp.quit) # noqa: F821 @@ -193,7 +193,7 @@ class MyWidget(QWidget): cannon_field.force_changed.connect(force.set_value) shoot = QPushButton("&Shoot") - shoot.setFont(QFont("Times", 18, QFont.Bold)) + shoot.setFont(QFont("Times", 18, QFont.Weight.Bold)) shoot.clicked.connect(cannon_field.shoot) diff --git a/examples/widgets/tutorials/cannon/t12.py b/examples/widgets/tutorials/cannon/t12.py index 827755008..4960797bc 100644 --- a/examples/widgets/tutorials/cannon/t12.py +++ b/examples/widgets/tutorials/cannon/t12.py @@ -38,7 +38,7 @@ class LCDRange(QWidget): self.slider.setRange(0, 99) self.slider.setValue(0) self.label = QLabel() - self.label.setAlignment(Qt.AlignHCenter | Qt.AlignTop) + self.label.setAlignment(Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop) self.slider.valueChanged.connect(lcd.display) self.slider.valueChanged.connect(self.value_changed) @@ -169,20 +169,20 @@ class CannonField(QWidget): self.paint_target(painter) def paint_shot(self, painter): - painter.setPen(Qt.NoPen) - painter.setBrush(Qt.black) + painter.setPen(Qt.PenStyle.NoPen) + painter.setBrush(Qt.GlobalColor.black) painter.drawRect(self.shot_rect()) def paint_target(self, painter): - painter.setPen(Qt.black) - painter.setBrush(Qt.red) + painter.setPen(Qt.GlobalColor.black) + painter.setBrush(Qt.GlobalColor.red) painter.drawRect(self.target_rect()) barrel_rect = QRect(33, -4, 15, 8) def paint_cannon(self, painter): - painter.setPen(Qt.NoPen) - painter.setBrush(Qt.blue) + painter.setPen(Qt.PenStyle.NoPen) + painter.setBrush(Qt.GlobalColor.blue) painter.save() painter.translate(0, self.height()) @@ -225,7 +225,7 @@ class MyWidget(QWidget): super().__init__(parent) quit = QPushButton("&Quit") - quit.setFont(QFont("Times", 18, QFont.Bold)) + quit.setFont(QFont("Times", 18, QFont.Weight.Bold)) quit.clicked.connect(qApp.quit) # noqa: F821 @@ -244,7 +244,7 @@ class MyWidget(QWidget): cannon_field.force_changed.connect(force.set_value) shoot = QPushButton("&Shoot") - shoot.setFont(QFont("Times", 18, QFont.Bold)) + shoot.setFont(QFont("Times", 18, QFont.Weight.Bold)) shoot.clicked.connect(cannon_field.shoot) diff --git a/examples/widgets/tutorials/cannon/t13.py b/examples/widgets/tutorials/cannon/t13.py index d15ef6831..c9b8bd5d7 100644 --- a/examples/widgets/tutorials/cannon/t13.py +++ b/examples/widgets/tutorials/cannon/t13.py @@ -39,8 +39,8 @@ class LCDRange(QWidget): self.slider.setRange(0, 99) self.slider.setValue(0) self.label = QLabel() - self.label.setAlignment(Qt.AlignHCenter | Qt.AlignTop) - self.label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) + self.label.setAlignment(Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop) + self.label.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed) self.slider.valueChanged.connect(lcd.display) self.slider.valueChanged.connect(self.value_changed) @@ -185,9 +185,9 @@ class CannonField(QWidget): def paintEvent(self, event): with QPainter(self) as painter: if self._game_ended: - painter.setPen(Qt.black) - painter.setFont(QFont("Courier", 48, QFont.Bold)) - painter.drawText(self.rect(), Qt.AlignCenter, "Game Over") + painter.setPen(Qt.GlobalColor.black) + painter.setFont(QFont("Courier", 48, QFont.Weight.Bold)) + painter.drawText(self.rect(), Qt.AlignmentFlag.AlignCenter, "Game Over") self.paint_cannon(painter) if self.is_shooting(): @@ -196,20 +196,20 @@ class CannonField(QWidget): self.paint_target(painter) def paint_shot(self, painter): - painter.setPen(Qt.NoPen) - painter.setBrush(Qt.black) + painter.setPen(Qt.PenStyle.NoPen) + painter.setBrush(Qt.GlobalColor.black) painter.drawRect(self.shot_rect()) def paint_target(self, painter): - painter.setPen(Qt.black) - painter.setBrush(Qt.red) + painter.setPen(Qt.GlobalColor.black) + painter.setBrush(Qt.GlobalColor.red) painter.drawRect(self.target_rect()) barrel_rect = QRect(33, -4, 15, 8) def paint_cannon(self, painter): - painter.setPen(Qt.NoPen) - painter.setBrush(Qt.blue) + painter.setPen(Qt.PenStyle.NoPen) + painter.setBrush(Qt.GlobalColor.blue) painter.save() painter.translate(0, self.height()) @@ -258,7 +258,7 @@ class GameBoard(QWidget): super().__init__(parent) quit = QPushButton("&Quit") - quit.setFont(QFont("Times", 18, QFont.Bold)) + quit.setFont(QFont("Times", 18, QFont.Weight.Bold)) quit.clicked.connect(qApp.quit) # noqa: F821 @@ -280,13 +280,13 @@ class GameBoard(QWidget): self._cannon_field.missed.connect(self.missed) shoot = QPushButton("&Shoot") - shoot.setFont(QFont("Times", 18, QFont.Bold)) + shoot.setFont(QFont("Times", 18, QFont.Weight.Bold)) shoot.clicked.connect(self.fire) self._cannon_field.can_shoot.connect(shoot.setEnabled) restart = QPushButton("&New Game") - restart.setFont(QFont("Times", 18, QFont.Bold)) + restart.setFont(QFont("Times", 18, QFont.Weight.Bold)) restart.clicked.connect(self.new_game) diff --git a/examples/widgets/tutorials/cannon/t14.py b/examples/widgets/tutorials/cannon/t14.py index ed35ede09..00674189b 100644 --- a/examples/widgets/tutorials/cannon/t14.py +++ b/examples/widgets/tutorials/cannon/t14.py @@ -40,8 +40,8 @@ class LCDRange(QWidget): self.slider.setRange(0, 99) self.slider.setValue(0) self.label = QLabel() - self.label.setAlignment(Qt.AlignHCenter | Qt.AlignTop) - self.label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) + self.label.setAlignment(Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop) + self.label.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed) self.slider.valueChanged.connect(lcd.display) self.slider.valueChanged.connect(self.value_changed) @@ -186,7 +186,7 @@ class CannonField(QWidget): self.update(region) def mousePressEvent(self, event): - if event.button() != Qt.LeftButton: + if event.button() != Qt.MouseButton.LeftButton: return if self.barrel_hit(event.position().toPoint()): self._barrel_pressed = True @@ -203,15 +203,15 @@ class CannonField(QWidget): self.set_angle(round(rad * 180 / math.pi)) def mouseReleaseEvent(self, event): - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self._barrel_pressed = False def paintEvent(self, event): with QPainter(self) as painter: if self._game_ended: - painter.setPen(Qt.black) - painter.setFont(QFont("Courier", 48, QFont.Bold)) - painter.drawText(self.rect(), Qt.AlignCenter, "Game Over") + painter.setPen(Qt.GlobalColor.black) + painter.setFont(QFont("Courier", 48, QFont.Weight.Bold)) + painter.drawText(self.rect(), Qt.AlignmentFlag.AlignCenter, "Game Over") self.paint_cannon(painter) self.paint_barrier(painter) @@ -221,25 +221,25 @@ class CannonField(QWidget): self.paint_target(painter) def paint_shot(self, painter): - painter.setPen(Qt.NoPen) - painter.setBrush(Qt.black) + painter.setPen(Qt.PenStyle.NoPen) + painter.setBrush(Qt.GlobalColor.black) painter.drawRect(self.shot_rect()) def paint_target(self, painter): - painter.setPen(Qt.black) - painter.setBrush(Qt.red) + painter.setPen(Qt.GlobalColor.black) + painter.setBrush(Qt.GlobalColor.red) painter.drawRect(self.target_rect()) def paint_barrier(self, painter): - painter.setPen(Qt.black) - painter.setBrush(Qt.yellow) + painter.setPen(Qt.GlobalColor.black) + painter.setBrush(Qt.GlobalColor.yellow) painter.drawRect(self.barrier_rect()) barrel_rect = QRect(33, -4, 15, 8) def paint_cannon(self, painter): - painter.setPen(Qt.NoPen) - painter.setBrush(Qt.blue) + painter.setPen(Qt.PenStyle.NoPen) + painter.setBrush(Qt.GlobalColor.blue) painter.save() painter.translate(0, self.height()) @@ -301,7 +301,7 @@ class GameBoard(QWidget): super().__init__(parent) quit = QPushButton("&Quit") - quit.setFont(QFont("Times", 18, QFont.Bold)) + quit.setFont(QFont("Times", 18, QFont.Weight.Bold)) quit.clicked.connect(qApp.quit) # noqa: F821 @@ -312,7 +312,7 @@ class GameBoard(QWidget): force.set_range(10, 50) cannon_box = QFrame() - cannon_box.setFrameStyle(QFrame.WinPanel | QFrame.Sunken) + cannon_box.setFrameStyle(QFrame.Shape.WinPanel | QFrame.Shadow.Sunken) self._cannon_field = CannonField() @@ -326,13 +326,13 @@ class GameBoard(QWidget): self._cannon_field.missed.connect(self.missed) shoot = QPushButton("&Shoot") - shoot.setFont(QFont("Times", 18, QFont.Bold)) + shoot.setFont(QFont("Times", 18, QFont.Weight.Bold)) shoot.clicked.connect(self.fire) self._cannon_field.can_shoot.connect(shoot.setEnabled) restart = QPushButton("&New Game") - restart.setFont(QFont("Times", 18, QFont.Bold)) + restart.setFont(QFont("Times", 18, QFont.Weight.Bold)) restart.clicked.connect(self.new_game) @@ -341,9 +341,9 @@ class GameBoard(QWidget): hits_label = QLabel("HITS") shots_left_label = QLabel("SHOTS LEFT") - QShortcut(QKeySequence(Qt.Key_Enter), self, self.fire) - QShortcut(QKeySequence(Qt.Key_Return), self, self.fire) - QShortcut(QKeySequence(Qt.CTRL | Qt.Key_Q), self, self.close) + QShortcut(QKeySequence(Qt.Key.Key_Enter), self, self.fire) + QShortcut(QKeySequence(Qt.Key.Key_Return), self, self.fire) + QShortcut(QKeySequence(Qt.Modifier.CTRL | Qt.Key.Key_Q), self, self.close) top_layout = QHBoxLayout() top_layout.addWidget(shoot) diff --git a/examples/widgets/tutorials/cannon/t2.py b/examples/widgets/tutorials/cannon/t2.py index 7379ba4d9..2b441391a 100644 --- a/examples/widgets/tutorials/cannon/t2.py +++ b/examples/widgets/tutorials/cannon/t2.py @@ -16,7 +16,7 @@ if __name__ == '__main__': quit = QPushButton("Quit") quit.resize(75, 30) - quit.setFont(QFont("Times", 18, QFont.Bold)) + quit.setFont(QFont("Times", 18, QFont.Weight.Bold)) quit.clicked.connect(app.quit) diff --git a/examples/widgets/tutorials/cannon/t3.py b/examples/widgets/tutorials/cannon/t3.py index ed7cf00e0..9befa772c 100644 --- a/examples/widgets/tutorials/cannon/t3.py +++ b/examples/widgets/tutorials/cannon/t3.py @@ -18,7 +18,7 @@ if __name__ == '__main__': window.resize(200, 120) quit = QPushButton("Quit", window) - quit.setFont(QFont("Times", 18, QFont.Bold)) + quit.setFont(QFont("Times", 18, QFont.Weight.Bold)) quit.setGeometry(10, 40, 180, 40) quit.clicked.connect(app.quit) diff --git a/examples/widgets/tutorials/cannon/t4.py b/examples/widgets/tutorials/cannon/t4.py index 199b65731..9f11de359 100644 --- a/examples/widgets/tutorials/cannon/t4.py +++ b/examples/widgets/tutorials/cannon/t4.py @@ -19,7 +19,7 @@ class MyWidget(QWidget): self.quit = QPushButton("Quit", self) self.quit.setGeometry(62, 40, 75, 30) - self.quit.setFont(QFont("Times", 18, QFont.Bold)) + self.quit.setFont(QFont("Times", 18, QFont.Weight.Bold)) self.quit.clicked.connect(qApp.quit) # noqa: F821 diff --git a/examples/widgets/tutorials/cannon/t5.py b/examples/widgets/tutorials/cannon/t5.py index 507204d9c..12f4847c8 100644 --- a/examples/widgets/tutorials/cannon/t5.py +++ b/examples/widgets/tutorials/cannon/t5.py @@ -18,7 +18,7 @@ class MyWidget(QWidget): super().__init__(parent) quit = QPushButton("Quit") - quit.setFont(QFont("Times", 18, QFont.Bold)) + quit.setFont(QFont("Times", 18, QFont.Weight.Bold)) lcd = QLCDNumber(2) diff --git a/examples/widgets/tutorials/cannon/t6.py b/examples/widgets/tutorials/cannon/t6.py index 155760154..04db4b51e 100644 --- a/examples/widgets/tutorials/cannon/t6.py +++ b/examples/widgets/tutorials/cannon/t6.py @@ -33,7 +33,7 @@ class MyWidget(QWidget): super().__init__(parent) quit = QPushButton("Quit") - quit.setFont(QFont("Times", 18, QFont.Bold)) + quit.setFont(QFont("Times", 18, QFont.Weight.Bold)) quit.clicked.connect(qApp.quit) # noqa: F821 layout = QVBoxLayout(self) diff --git a/examples/widgets/tutorials/cannon/t7.py b/examples/widgets/tutorials/cannon/t7.py index e7864bdc5..2ef051e21 100644 --- a/examples/widgets/tutorials/cannon/t7.py +++ b/examples/widgets/tutorials/cannon/t7.py @@ -46,7 +46,7 @@ class MyWidget(QWidget): super().__init__(parent) quit = QPushButton("Quit") - quit.setFont(QFont("Times", 18, QFont.Bold)) + quit.setFont(QFont("Times", 18, QFont.Weight.Bold)) quit.clicked.connect(qApp.quit) # noqa: F821 previous_range = None diff --git a/examples/widgets/tutorials/cannon/t8.py b/examples/widgets/tutorials/cannon/t8.py index 3b298f492..560d73cff 100644 --- a/examples/widgets/tutorials/cannon/t8.py +++ b/examples/widgets/tutorials/cannon/t8.py @@ -87,7 +87,7 @@ class MyWidget(QWidget): super().__init__(parent) quit = QPushButton("Quit") - quit.setFont(QFont("Times", 18, QFont.Bold)) + quit.setFont(QFont("Times", 18, QFont.Weight.Bold)) quit.clicked.connect(qApp.quit) # noqa: F821 diff --git a/examples/widgets/tutorials/cannon/t9.py b/examples/widgets/tutorials/cannon/t9.py index 566f76d84..25d2554fd 100644 --- a/examples/widgets/tutorials/cannon/t9.py +++ b/examples/widgets/tutorials/cannon/t9.py @@ -79,8 +79,8 @@ class CannonField(QWidget): def paintEvent(self, event): with QPainter(self) as painter: - painter.setPen(Qt.NoPen) - painter.setBrush(Qt.blue) + painter.setPen(Qt.PenStyle.NoPen) + painter.setBrush(Qt.GlobalColor.blue) painter.translate(0, self.rect().height()) painter.drawPie(QRect(-35, -35, 70, 70), 0, 90 * 16) @@ -93,7 +93,7 @@ class MyWidget(QWidget): super().__init__(parent) quit = QPushButton("Quit") - quit.setFont(QFont("Times", 18, QFont.Bold)) + quit.setFont(QFont("Times", 18, QFont.Weight.Bold)) quit.clicked.connect(qApp.quit) # noqa: F821 diff --git a/examples/widgets/tutorials/modelview/2_formatting.py b/examples/widgets/tutorials/modelview/2_formatting.py index 07833bbd5..6fef1d596 100644 --- a/examples/widgets/tutorials/modelview/2_formatting.py +++ b/examples/widgets/tutorials/modelview/2_formatting.py @@ -43,15 +43,15 @@ class MyModel(QAbstractTableModel): elif role == Qt.ItemDataRole.BackgroundRole: if row == 1 and col == 2: # change background only for cell(1,2) - return QBrush(Qt.red) + return QBrush(Qt.GlobalColor.red) elif role == Qt.ItemDataRole.TextAlignmentRole: if row == 1 and col == 1: # change text alignment only for cell(1,1) - return Qt.AlignRight | Qt.AlignVCenter + return Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter elif role == Qt.ItemDataRole.CheckStateRole: if row == 1 and col == 0: # add a checkbox to cell(1,0) - return Qt.Checked + return Qt.CheckState.Checked return None #! [1] diff --git a/examples/widgets/widgets/charactermap/characterwidget.py b/examples/widgets/widgets/charactermap/characterwidget.py index e96dacf9e..91c040814 100644 --- a/examples/widgets/widgets/charactermap/characterwidget.py +++ b/examples/widgets/widgets/charactermap/characterwidget.py @@ -84,7 +84,7 @@ class CharacterWidget(QWidget): QToolTip.showText(event.globalPosition().toPoint(), text, self) def mousePressEvent(self, event): - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self._last_key = self._unicode_from_pos(event.position().toPoint()) if self._last_key != -1: c = chr(self._last_key) @@ -99,14 +99,14 @@ class CharacterWidget(QWidget): def render(self, event, painter): painter = QPainter(self) - painter.fillRect(event.rect(), QBrush(Qt.white)) + painter.fillRect(event.rect(), QBrush(Qt.GlobalColor.white)) painter.setFont(self._display_font) redraw_rect = event.rect() begin_row = int(redraw_rect.top() / self._square_size) end_row = int(redraw_rect.bottom() / self._square_size) begin_column = int(redraw_rect.left() / self._square_size) end_column = int(redraw_rect.right() / self._square_size) - painter.setPen(QPen(Qt.gray)) + painter.setPen(QPen(Qt.GlobalColor.gray)) for row in range(begin_row, end_row + 1): for column in range(begin_column, end_column + 1): x = int(column * self._square_size) @@ -114,7 +114,7 @@ class CharacterWidget(QWidget): painter.drawRect(x, y, self._square_size, self._square_size) font_metrics = QFontMetrics(self._display_font) - painter.setPen(QPen(Qt.black)) + painter.setPen(QPen(Qt.GlobalColor.black)) for row in range(begin_row, end_row + 1): for column in range(begin_column, end_column + 1): key = int(row * COLUMNS + column) @@ -125,7 +125,8 @@ class CharacterWidget(QWidget): if key == self._last_key: painter.fillRect(column * self._square_size + 1, row * self._square_size + 1, - self._square_size, self._square_size, QBrush(Qt.red)) + self._square_size, self._square_size, + QBrush(Qt.GlobalColor.red)) text = chr(key) painter.drawText(column * self._square_size + (self._square_size / 2) diff --git a/examples/widgets/widgets/charactermap/fontinfodialog.py b/examples/widgets/widgets/charactermap/fontinfodialog.py index 43b0c1145..9763008e2 100644 --- a/examples/widgets/widgets/charactermap/fontinfodialog.py +++ b/examples/widgets/widgets/charactermap/fontinfodialog.py @@ -24,7 +24,7 @@ class FontInfoDialog(QDialog): text_edit.setReadOnly(True) text_edit.setFont(QFontDatabase.systemFont(QFontDatabase.FixedFont)) main_layout.addWidget(text_edit) - button_box = QDialogButtonBox(QDialogButtonBox.Close, self) + button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Close, self) button_box.rejected.connect(self.reject) main_layout.addWidget(button_box) diff --git a/examples/widgets/widgets/charactermap/mainwindow.py b/examples/widgets/widgets/charactermap/mainwindow.py index a2dbb3b25..88d738f8b 100644 --- a/examples/widgets/widgets/charactermap/mainwindow.py +++ b/examples/widgets/widgets/charactermap/mainwindow.py @@ -37,10 +37,10 @@ class MainWindow(QMainWindow): self._filter_label = QLabel("Filter:") self._filter_combo = QComboBox() - self._filter_combo.addItem("All", int(QFontComboBox.AllFonts.value)) - self._filter_combo.addItem("Scalable", int(QFontComboBox.ScalableFonts.value)) - self._filter_combo.addItem("Monospaced", int(QFontComboBox.MonospacedFonts.value)) - self._filter_combo.addItem("Proportional", int(QFontComboBox.ProportionalFonts.value)) + self._filter_combo.addItem("All", QFontComboBox.FontFilter.AllFonts) + self._filter_combo.addItem("Scalable", QFontComboBox.FontFilter.ScalableFonts) + self._filter_combo.addItem("Monospaced", QFontComboBox.FontFilter.MonospacedFonts) + self._filter_combo.addItem("Proportional", QFontComboBox.FontFilter.ProportionalFonts) self._filter_combo.setCurrentIndex(0) self._filter_combo.currentIndexChanged.connect(self.filter_changed) @@ -117,7 +117,7 @@ class MainWindow(QMainWindow): @Slot(int) def filter_changed(self, f): - filter = QFontComboBox.FontFilter(self._filter_combo.itemData(f)) + filter = self._filter_combo.itemData(f) self._font_combo.setFontFilters(filter) count = self._font_combo.count() self.statusBar().showMessage(f"{count} font(s) found") @@ -163,6 +163,6 @@ class MainWindow(QMainWindow): screen_geometry = self.screen().geometry() dialog = FontInfoDialog(self) dialog.setWindowTitle("Fonts") - dialog.setAttribute(Qt.WA_DeleteOnClose) + dialog.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose) dialog.resize(screen_geometry.width() / 4, screen_geometry.height() / 4) dialog.show() diff --git a/examples/widgets/widgets/digitalclock/digitalclock.py b/examples/widgets/widgets/digitalclock/digitalclock.py index 53c40c823..fba0a4374 100644 --- a/examples/widgets/widgets/digitalclock/digitalclock.py +++ b/examples/widgets/widgets/digitalclock/digitalclock.py @@ -10,7 +10,7 @@ from PySide6.QtWidgets import QApplication, QLCDNumber class DigitalClock(QLCDNumber): def __init__(self, parent=None): super().__init__(parent) - self.setSegmentStyle(QLCDNumber.Filled) + self.setSegmentStyle(QLCDNumber.SegmentStyle.Filled) self.setDigitCount(8) self.timer = QTimer(self) diff --git a/examples/widgets/widgets/tetrix/tetrix.py b/examples/widgets/widgets/tetrix/tetrix.py index 130843b03..4428b332e 100644 --- a/examples/widgets/widgets/tetrix/tetrix.py +++ b/examples/widgets/widgets/tetrix/tetrix.py @@ -33,23 +33,23 @@ class TetrixWindow(QWidget): self.board = TetrixBoard() next_piece_label = QLabel() - next_piece_label.setFrameStyle(QFrame.Box | QFrame.Raised) - next_piece_label.setAlignment(Qt.AlignCenter) + next_piece_label.setFrameStyle(QFrame.Shape.Box | QFrame.Shadow.Raised) + next_piece_label.setAlignment(Qt.AlignmentFlag.AlignCenter) self.board.set_next_piece_label(next_piece_label) score_lcd = QLCDNumber(5) - score_lcd.setSegmentStyle(QLCDNumber.Filled) + score_lcd.setSegmentStyle(QLCDNumber.SegmentStyle.Filled) level_lcd = QLCDNumber(2) - level_lcd.setSegmentStyle(QLCDNumber.Filled) + level_lcd.setSegmentStyle(QLCDNumber.SegmentStyle.Filled) lines_lcd = QLCDNumber(5) - lines_lcd.setSegmentStyle(QLCDNumber.Filled) + lines_lcd.setSegmentStyle(QLCDNumber.SegmentStyle.Filled) start_button = QPushButton("&Start") - start_button.setFocusPolicy(Qt.NoFocus) + start_button.setFocusPolicy(Qt.FocusPolicy.NoFocus) quit_button = QPushButton("&Quit") - quit_button.setFocusPolicy(Qt.NoFocus) + quit_button.setFocusPolicy(Qt.FocusPolicy.NoFocus) pause_button = QPushButton("&Pause") - pause_button.setFocusPolicy(Qt.NoFocus) + pause_button.setFocusPolicy(Qt.FocusPolicy.NoFocus) start_button.clicked.connect(self.board.start) pause_button.clicked.connect(self.board.pause) @@ -77,7 +77,7 @@ class TetrixWindow(QWidget): def create_label(self, text): lbl = QLabel(text) - lbl.setAlignment(Qt.AlignHCenter | Qt.AlignBottom) + lbl.setAlignment(Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignBottom) return lbl @@ -107,8 +107,8 @@ class TetrixBoard(QFrame): self.level = 0 self.board = None - self.setFrameStyle(QFrame.Panel | QFrame.Sunken) - self.setFocusPolicy(Qt.StrongFocus) + self.setFrameStyle(QFrame.Shape.Panel | QFrame.Shadow.Sunken) + self.setFocusPolicy(Qt.FocusPolicy.StrongFocus) self._is_started = False self._is_paused = False self.clear_board() @@ -181,7 +181,7 @@ class TetrixBoard(QFrame): rect = self.contentsRect() if self._is_paused: - painter.drawText(rect, Qt.AlignCenter, "Pause") + painter.drawText(rect, Qt.AlignmentFlag.AlignCenter, "Pause") return board_top = rect.bottom() - TetrixBoard.board_height * self.square_height() @@ -209,17 +209,17 @@ class TetrixBoard(QFrame): return key = event.key() - if key == Qt.Key_Left: + if key == Qt.Key.Key_Left: self.try_move(self._cur_piece, self._cur_x - 1, self._cur_y) - elif key == Qt.Key_Right: + elif key == Qt.Key.Key_Right: self.try_move(self._cur_piece, self._cur_x + 1, self._cur_y) - elif key == Qt.Key_Down: + elif key == Qt.Key.Key_Down: self.try_move(self._cur_piece.rotated_right(), self._cur_x, self._cur_y) - elif key == Qt.Key_Up: + elif key == Qt.Key.Key_Up: self.try_move(self._cur_piece.rotated_left(), self._cur_x, self._cur_y) - elif key == Qt.Key_Space: + elif key == Qt.Key.Key_Space: self.drop_down() - elif key == Qt.Key_D: + elif key == Qt.Key.Key_D: self.one_line_down() else: super(TetrixBoard, self).keyPressEvent(event) diff --git a/examples/widgets/widgetsgallery/widgetgallery.py b/examples/widgets/widgetsgallery/widgetgallery.py index 7a238b443..972ffbaa0 100644 --- a/examples/widgets/widgetsgallery/widgetgallery.py +++ b/examples/widgets/widgetsgallery/widgetgallery.py @@ -154,7 +154,7 @@ class WidgetGallery(QDialog): disable_widgets_checkbox.toggled.connect(simple_input_widgets_groupbox.setDisabled) help_shortcut = QShortcut(self) - help_shortcut.setKey(QKeySequence.HelpContents) + help_shortcut.setKey(QKeySequence.StandardKey.HelpContents) help_shortcut.activated.connect(self.help_on_current_widget) top_layout = QHBoxLayout() @@ -165,8 +165,8 @@ class WidgetGallery(QDialog): top_layout.addStretch(1) top_layout.addWidget(disable_widgets_checkbox) - dialog_buttonbox = QDialogButtonBox(QDialogButtonBox.Help - | QDialogButtonBox.Close) + dialog_buttonbox = QDialogButtonBox(QDialogButtonBox.StandardButton.Help + | QDialogButtonBox.StandardButton.Close) init_widget(dialog_buttonbox, "dialogButtonBox") dialog_buttonbox.helpRequested.connect(launch_module_help) dialog_buttonbox.rejected.connect(self.reject) @@ -224,7 +224,7 @@ class WidgetGallery(QDialog): init_widget(menu_toolbutton, "menuButton") menu_toolbutton.setText("Menu Button") tool_menu = QMenu(menu_toolbutton) - menu_toolbutton.setPopupMode(QToolButton.InstantPopup) + menu_toolbutton.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup) tool_menu.addAction("Option") tool_menu.addSeparator() action = tool_menu.addAction("Checkable Option") @@ -257,7 +257,7 @@ class WidgetGallery(QDialog): checkbox = QCheckBox("Tri-state check box") init_widget(checkbox, "checkBox") checkbox.setTristate(True) - checkbox.setCheckState(Qt.PartiallyChecked) + checkbox.setCheckState(Qt.CheckState.PartiallyChecked) checkable_layout = QVBoxLayout() checkable_layout.addWidget(radiobutton_1) @@ -300,7 +300,7 @@ class WidgetGallery(QDialog): def create_itemview_tabwidget(self): result = QTabWidget() init_widget(result, "bottomLeftTabWidget") - result.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Ignored) + result.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Ignored) tree_view = QTreeView() init_widget(tree_view, "treeView") @@ -325,7 +325,7 @@ class WidgetGallery(QDialog): icon_mode_listview = QListView() init_widget(icon_mode_listview, "iconModeListView") - icon_mode_listview.setViewMode(QListView.IconMode) + icon_mode_listview.setViewMode(QListView.ViewMode.IconMode) icon_mode_listview.setModel(list_model) result.addTab(embed_into_hbox_layout(tree_view), "Tree View") @@ -344,7 +344,7 @@ class WidgetGallery(QDialog): lineedit = QLineEdit("s3cRe7") init_widget(lineedit, "lineEdit") lineedit.setClearButtonEnabled(True) - lineedit.setEchoMode(QLineEdit.Password) + lineedit.setEchoMode(QLineEdit.EchoMode.Password) spin_box = QSpinBox() init_widget(spin_box, "spinBox") |