修复依赖缺失问题
This commit is contained in:
+63
-21
@@ -1,7 +1,7 @@
|
||||
"""标准对话框(QMessageBox / QInputDialog / QFileDialog)与当前主题一致。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtCore import Qt, QTimer
|
||||
from PyQt6.QtGui import QTextOption
|
||||
from PyQt6.QtWidgets import (
|
||||
QFileDialog,
|
||||
@@ -37,7 +37,6 @@ def stylesheet() -> str:
|
||||
}}
|
||||
QMessageBox QLabel#qt_msgbox_label {{
|
||||
min-width: 200px;
|
||||
max-width: 560px;
|
||||
}}
|
||||
QMessageBox QLabel#qt_msgboxex_icon_label {{
|
||||
min-width: 28px;
|
||||
@@ -140,31 +139,74 @@ def _apply(w: QWidget | None) -> None:
|
||||
|
||||
|
||||
def _prepare_qmessagebox(msg: QMessageBox) -> None:
|
||||
"""让提示框按内容换行并自适应宽高(避免固定宽度截断文字)。"""
|
||||
lbl = msg.findChild(QLabel, "qt_msgbox_label")
|
||||
if lbl is not None:
|
||||
lbl.setWordWrap(True)
|
||||
lbl.setTextFormat(Qt.TextFormat.PlainText)
|
||||
# 无空格长中文也能在边界处断行,而不是整段挤在一行被裁切
|
||||
try:
|
||||
lbl.setWordWrapMode(QTextOption.WrapMode.WrapAnywhere)
|
||||
except AttributeError:
|
||||
pass
|
||||
lbl.setMinimumWidth(200)
|
||||
lbl.setMaximumWidth(560)
|
||||
lbl.setSizePolicy(
|
||||
QSizePolicy.Policy.Preferred,
|
||||
QSizePolicy.Policy.MinimumExpanding,
|
||||
)
|
||||
lay = msg.layout()
|
||||
if lay is not None:
|
||||
lay.activate()
|
||||
"""让提示框按内容换行并自适应宽高。"""
|
||||
def _tune_labels() -> None:
|
||||
# QMessageBox 里通常有两段文字:
|
||||
# - qt_msgbox_label(主文本)
|
||||
# - qt_msgbox_informativelabel(辅助文本/更长的提示)
|
||||
# 部分平台会在显示/布局后才创建这些 label,因此这里支持延迟执行一次。
|
||||
for obj_name in ("qt_msgbox_label", "qt_msgbox_informativelabel"):
|
||||
w = msg.findChild(QWidget, obj_name)
|
||||
if w is None:
|
||||
continue
|
||||
|
||||
if hasattr(w, "setWordWrap"):
|
||||
try:
|
||||
w.setWordWrap(True) # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
pass
|
||||
if hasattr(w, "setTextFormat"):
|
||||
try:
|
||||
w.setTextFormat(Qt.TextFormat.PlainText) # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
pass
|
||||
if hasattr(w, "setWordWrapMode"):
|
||||
try:
|
||||
w.setWordWrapMode(QTextOption.WrapMode.WrapAnywhere) # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
pass
|
||||
if hasattr(w, "setTextElideMode"):
|
||||
try:
|
||||
w.setTextElideMode(Qt.TextElideMode.ElideNone) # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
pass
|
||||
if hasattr(w, "setMinimumWidth"):
|
||||
try:
|
||||
w.setMinimumWidth(0) # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
pass
|
||||
if hasattr(w, "setMaximumWidth"):
|
||||
try:
|
||||
w.setMaximumWidth(16777215) # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
pass
|
||||
if hasattr(w, "setSizePolicy"):
|
||||
try:
|
||||
w.setSizePolicy(
|
||||
QSizePolicy.Policy.Expanding,
|
||||
QSizePolicy.Policy.MinimumExpanding,
|
||||
) # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
pass
|
||||
msg.setSizePolicy(
|
||||
QSizePolicy.Policy.Preferred,
|
||||
QSizePolicy.Policy.Preferred,
|
||||
)
|
||||
msg.setMinimumSize(0, 0)
|
||||
msg.setMaximumSize(16777215, 16777215)
|
||||
|
||||
lay = msg.layout()
|
||||
if lay is not None:
|
||||
# QMessageBox 内部通常是 QGridLayout:第 1 列是文本列
|
||||
# 某些主题/平台会让文本列偏窄从而触发省略,这里显式拉伸该列并设置最小宽度。
|
||||
try:
|
||||
lay.setColumnStretch(1, 1)
|
||||
except Exception:
|
||||
pass
|
||||
lay.activate()
|
||||
_tune_labels()
|
||||
msg.adjustSize()
|
||||
QTimer.singleShot(0, lambda: (_tune_labels(), msg.adjustSize()))
|
||||
|
||||
|
||||
def question(
|
||||
|
||||
Reference in New Issue
Block a user