Skip to content

Commit 7048777

Browse files
committed
Add support for Qt6
While still falling back to Qt5 as needed.
1 parent 9d86d60 commit 7048777

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/napari_imagej/widgets/widget_utils.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,19 @@ def __init__(self, title: str, error_message: str, *args, **kwargs):
146146
textHeight = textSize.height() + 100
147147
self.resize(textWidth, textHeight)
148148
# Maximum size - ~80% of the user's screen
149-
screen_size = QApplication.desktop().screenGeometry()
150-
self.setMaximumSize(
151-
int(screen_size.width() * 0.8), int(screen_size.height() * 0.8)
152-
)
149+
screen_size = None
150+
try:
151+
screen_size = QApplication.primaryScreen().geometry() # PyQt6
152+
except Exception:
153+
pass
154+
if not screen_size:
155+
try:
156+
screen_size = QApplication.desktop().screenGeometry() # PyQt5
157+
except Exception:
158+
pass
159+
screen_width = screen_size.width() if screen_size else 1024
160+
screen_height = screen_size.height() if screen_size else 768
161+
self.setMaximumSize(int(screen_width * 0.8), int(screen_height * 0.8))
153162

154163
btn_box = QDialogButtonBox(QDialogButtonBox.Ok)
155164
btn_box.accepted.connect(self.accept)

tests/widgets/test_menu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def popup_handler(asserter) -> Callable[[str, Callable[[], None]], None]:
7979
def handle_popup(
8080
popup_generator: Callable[[], None], popup_handler: Callable[[QDialog], bool]
8181
):
82-
# # Start the handler in a new thread
82+
# Start the handler in a new thread
8383
class Handler(QRunnable):
8484
# Test popup when running headlessly
8585
def run(self) -> None:
@@ -89,7 +89,7 @@ def run(self) -> None:
8989
asserter(lambda: QApplication.activeModalWidget() is not widget)
9090

9191
def passed(self) -> bool:
92-
return self._passed
92+
return getattr(self, '_passed', False)
9393

9494
runnable = Handler()
9595
QThreadPool.globalInstance().start(runnable)

tests/widgets/test_result_tree.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ def test_right_click(fixed_tree: SearcherTreeView, asserter):
120120
# First, assert the policy
121121
assert fixed_tree.contextMenuPolicy() == Qt.CustomContextMenu
122122
# Then, grab an arbitratry Search Result
123-
idx = fixed_tree.model().index(0, 0).child(0, 0)
123+
parent_idx = fixed_tree.model().index(0, 0)
124+
idx = (
125+
parent_idx.child(0, 0) # PyQt5
126+
if hasattr(parent_idx, "child")
127+
else fixed_tree.model().index(0, 0, parent_idx) # PyQt6
128+
)
124129
rect = fixed_tree.visualRect(idx)
125130
item = fixed_tree.model().itemFromIndex(idx)
126131
# Find its SearchActions

0 commit comments

Comments
 (0)