Skip to content

Commit 62391c6

Browse files
committed
fix(ui): use platform button ordering for Modal class
1 parent b612c97 commit 62391c6

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

‎src/tagstudio/qt/controllers/changelog_modal.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
QTextFormat,
2525
)
2626
from PySide6.QtNetwork import QNetworkAccessManager, QNetworkReply, QNetworkRequest
27+
from PySide6.QtWidgets import QDialogButtonBox
2728

2829
from tagstudio.core.constants import DOCS_URL, GITHUB_REPO_URL
2930
from tagstudio.core.utils.types import unwrap
@@ -313,8 +314,8 @@ def parent_post_init(self) -> None:
313314
assert isinstance(modal_view, ModalView)
314315
close_button = unwrap(self.done_button)
315316
close_button.setText(Translations["generic.close"])
316-
modal_view.button_layout.insertWidget(
317-
modal_view.button_layout.indexOf(close_button), self.layout().view_more_button
317+
modal_view.button_box.addButton(
318+
self.layout().view_more_button, QDialogButtonBox.ButtonRole.ActionRole
318319
)
319320

320321
# NOTE: A lot of the styling is similar to the "About" window, which eventually needs to be

‎src/tagstudio/qt/views/modal_view.py‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import structlog
66
from PySide6.QtCore import Qt
7-
from PySide6.QtWidgets import QHBoxLayout, QLabel, QPushButton, QVBoxLayout, QWidget
7+
from PySide6.QtWidgets import QDialogButtonBox, QLabel, QVBoxLayout
88

99
from tagstudio.i18n.translations import Translations
1010
from tagstudio.qt.controllers.modal_content import ModalContent
@@ -28,28 +28,26 @@ def __init__(
2828
self.content_widget = content_widget
2929
self.setContentsMargins(PAD, PAD if inline_title else PAD * 2, PAD, PAD)
3030

31-
self.button_container = QWidget()
32-
self.button_layout = QHBoxLayout(self.button_container)
33-
self.button_layout.setContentsMargins(PAD, PAD, PAD, PAD)
34-
self.button_layout.addStretch(1)
31+
self.button_box = QDialogButtonBox()
32+
self.button_box.setContentsMargins(PAD, PAD, PAD, PAD)
3533

36-
# [Done]
37-
# - OR -
38-
# [Cancel] [Save]
3934
if not is_savable:
40-
done_button = QPushButton(Translations["generic.done"])
35+
done_button = self.button_box.addButton(
36+
Translations["generic.done"], QDialogButtonBox.ButtonRole.AcceptRole
37+
)
4138
done_button.setAutoDefault(True)
4239
self.content_widget.done_button = done_button
43-
self.button_layout.addWidget(done_button)
4440
else:
45-
cancel_button = QPushButton(Translations["generic.cancel"])
41+
cancel_button = self.button_box.addButton(
42+
Translations["generic.cancel"], QDialogButtonBox.ButtonRole.RejectRole
43+
)
4644
self.content_widget.cancel_button = cancel_button
47-
self.button_layout.addWidget(cancel_button)
4845

49-
save_button = QPushButton(Translations["generic.save"])
46+
save_button = self.button_box.addButton(
47+
Translations["generic.save"], QDialogButtonBox.ButtonRole.AcceptRole
48+
)
5049
save_button.setAutoDefault(True)
5150
self.content_widget.save_button = save_button
52-
self.button_layout.addWidget(save_button)
5351

5452
if inline_title:
5553
self.title_label = QLabel()
@@ -61,4 +59,4 @@ def __init__(
6159

6260
self.addWidget(content_widget)
6361
self.setStretch(1, 2)
64-
self.addWidget(self.button_container)
62+
self.addWidget(self.button_box)

0 commit comments

Comments
 (0)