Skip to content

Commit

Permalink
Do not use native dialog for reset shortcuts (#6493)
Browse files Browse the repository at this point in the history
# References and relevant issues
closes #6490

# Description

Since Qt6==6.5.0 on Macos, the Qt starts using native dialog even if it
does not support all buttons (in our case
`QMessageBox.StandardButton.RestoreDefaults`).

This solution is inspired by comments from
https://bugreports.qt.io/browse/QTBUG-116757

If someone has time, please try to open the Bug report there. After the
last discussions about patching enum, I do not feel fluent enough to
write in English to talk with them.

An alternative solution will be to change the button on the supported
one. Or change the native flag globally, but the second one may impact
File Dialogs.

---------

Co-authored-by: Peter Sobolewski <pete.sd@gmail.com>
  • Loading branch information
Czaki and psobolewskiPhD committed Dec 14, 2023
1 parent 4128733 commit cd50d92
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
16 changes: 14 additions & 2 deletions napari/_qt/dialogs/preferences_dialog.py
Expand Up @@ -4,6 +4,7 @@

from qtpy.QtCore import QSize, Qt, Signal
from qtpy.QtWidgets import (
QApplication,
QDialog,
QHBoxLayout,
QListWidget,
Expand Down Expand Up @@ -209,12 +210,23 @@ def _get_page_dict(self, field: 'ModelField') -> Tuple[dict, dict]:

def _restore_default_dialog(self):
"""Launches dialog to confirm restore settings choice."""
prev = QApplication.instance().testAttribute(
Qt.ApplicationAttribute.AA_DontUseNativeDialogs
)
QApplication.instance().setAttribute(
Qt.ApplicationAttribute.AA_DontUseNativeDialogs, True
)

response = QMessageBox.question(
self,
trans._("Restore Settings"),
trans._("Are you sure you want to restore default settings?"),
QMessageBox.RestoreDefaults | QMessageBox.Cancel,
QMessageBox.RestoreDefaults,
QMessageBox.StandardButton.RestoreDefaults
| QMessageBox.StandardButton.Cancel,
QMessageBox.StandardButton.RestoreDefaults,
)
QApplication.instance().setAttribute(
Qt.ApplicationAttribute.AA_DontUseNativeDialogs, prev
)
if response == QMessageBox.RestoreDefaults:
self._settings.reset()
Expand Down
16 changes: 13 additions & 3 deletions napari/_qt/widgets/qt_keyboard_settings.py
Expand Up @@ -6,6 +6,7 @@
from qtpy.QtGui import QKeySequence
from qtpy.QtWidgets import (
QAbstractItemView,
QApplication,
QComboBox,
QHBoxLayout,
QItemDelegate,
Expand Down Expand Up @@ -134,13 +135,22 @@ def __init__(

def restore_defaults(self):
"""Launches dialog to confirm restore choice."""

prev = QApplication.instance().testAttribute(
Qt.ApplicationAttribute.AA_DontUseNativeDialogs
)
QApplication.instance().setAttribute(
Qt.ApplicationAttribute.AA_DontUseNativeDialogs, True
)
response = QMessageBox.question(
self,
trans._("Restore Shortcuts"),
trans._("Are you sure you want to restore default shortcuts?"),
QMessageBox.RestoreDefaults | QMessageBox.Cancel,
QMessageBox.RestoreDefaults,
QMessageBox.StandardButton.RestoreDefaults
| QMessageBox.StandardButton.Cancel,
QMessageBox.StandardButton.RestoreDefaults,
)
QApplication.instance().setAttribute(
Qt.ApplicationAttribute.AA_DontUseNativeDialogs, prev
)

if response == QMessageBox.RestoreDefaults:
Expand Down

0 comments on commit cd50d92

Please sign in to comment.