Merge pull request #1479 from ynput/bugfix/avoid-using-qapp-desktop

UI: Avoid using QApplication desktop
This commit is contained in:
Jakub Trllo 2025-10-13 13:44:40 +02:00 committed by GitHub
commit 2cfb52ce02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -41,7 +41,7 @@ class ScrollMessageBox(QtWidgets.QDialog):
""" """
def __init__(self, icon, title, messages, cancelable=False): def __init__(self, icon, title, messages, cancelable=False):
super(ScrollMessageBox, self).__init__() super().__init__()
self.setWindowTitle(title) self.setWindowTitle(title)
self.icon = icon self.icon = icon
@ -49,8 +49,6 @@ class ScrollMessageBox(QtWidgets.QDialog):
self.setWindowFlags(QtCore.Qt.WindowTitleHint) self.setWindowFlags(QtCore.Qt.WindowTitleHint)
layout = QtWidgets.QVBoxLayout(self)
scroll_widget = QtWidgets.QScrollArea(self) scroll_widget = QtWidgets.QScrollArea(self)
scroll_widget.setWidgetResizable(True) scroll_widget.setWidgetResizable(True)
content_widget = QtWidgets.QWidget(self) content_widget = QtWidgets.QWidget(self)
@ -63,14 +61,8 @@ class ScrollMessageBox(QtWidgets.QDialog):
content_layout.addWidget(label_widget) content_layout.addWidget(label_widget)
message_len = max(message_len, len(message)) message_len = max(message_len, len(message))
# guess size of scrollable area # Set minimum width
# WARNING: 'desktop' method probably won't work in PySide6 scroll_widget.setMinimumWidth(360)
desktop = QtWidgets.QApplication.desktop()
max_width = desktop.availableGeometry().width()
scroll_widget.setMinimumWidth(
min(max_width, message_len * 6)
)
layout.addWidget(scroll_widget)
buttons = QtWidgets.QDialogButtonBox.Ok buttons = QtWidgets.QDialogButtonBox.Ok
if cancelable: if cancelable:
@ -86,7 +78,9 @@ class ScrollMessageBox(QtWidgets.QDialog):
btn.clicked.connect(self._on_copy_click) btn.clicked.connect(self._on_copy_click)
btn_box.addButton(btn, QtWidgets.QDialogButtonBox.NoRole) btn_box.addButton(btn, QtWidgets.QDialogButtonBox.NoRole)
layout.addWidget(btn_box) main_layout = QtWidgets.QVBoxLayout(self)
main_layout.addWidget(scroll_widget, 1)
main_layout.addWidget(btn_box, 0)
def _on_copy_click(self): def _on_copy_click(self):
clipboard = QtWidgets.QApplication.clipboard() clipboard = QtWidgets.QApplication.clipboard()
@ -104,7 +98,7 @@ class SimplePopup(QtWidgets.QDialog):
on_clicked = QtCore.Signal() on_clicked = QtCore.Signal()
def __init__(self, parent=None, *args, **kwargs): def __init__(self, parent=None, *args, **kwargs):
super(SimplePopup, self).__init__(parent=parent, *args, **kwargs) super().__init__(parent=parent, *args, **kwargs)
# Set default title # Set default title
self.setWindowTitle("Popup") self.setWindowTitle("Popup")
@ -161,7 +155,7 @@ class SimplePopup(QtWidgets.QDialog):
geo = self._calculate_window_geometry() geo = self._calculate_window_geometry()
self.setGeometry(geo) self.setGeometry(geo)
return super(SimplePopup, self).showEvent(event) return super().showEvent(event)
def _on_clicked(self): def _on_clicked(self):
"""Callback for when the 'show' button is clicked. """Callback for when the 'show' button is clicked.
@ -228,9 +222,7 @@ class PopupUpdateKeys(SimplePopup):
on_clicked_state = QtCore.Signal(bool) on_clicked_state = QtCore.Signal(bool)
def __init__(self, parent=None, *args, **kwargs): def __init__(self, parent=None, *args, **kwargs):
super(PopupUpdateKeys, self).__init__( super().__init__(parent=parent, *args, **kwargs)
parent=parent, *args, **kwargs
)
layout = self.layout() layout = self.layout()