Skip to content

The only downloader you need. 下载器的集大成者。

feat(TreeView): 选择文件对话框按标题长度自动加宽

XiaoYouChR178091009266
diff --git a/app/view/components/tree_view.py b/app/view/components/tree_view.py
index c73c5edb..f62e765d 100644
--- a/app/view/components/tree_view.py
+++ b/app/view/components/tree_view.py
@@ -46,17 +46,19 @@ class AutoSizingTreeView(TreeView):
header = self.header()
if header.count() == 0:
return super().sizeHint().width()
- return header.length() + self.frameWidth() * 2 + self.verticalScrollBar().sizeHint().width()
+ columns = sum(max(self.sizeHintForColumn(i), header.sectionSizeHint(i)) for i in range(header.count()))
+ return columns + self.frameWidth() * 2 + self.verticalScrollBar().sizeHint().width()
- def _sizeForRows(self, count: int) -> QSize:
+ def _heightForRows(self, count: int) -> int:
headerHeight = self.header().height() if self.header().isVisible() else 0
- return QSize(self._contentWidth(), headerHeight + count * self._rowHeight() + 4)
+ return headerHeight + count * self._rowHeight() + 4
def minimumSizeHint(self) -> QSize:
- return self._sizeForRows(min(self._minimumVisibleRows, self._visibleRowCount()))
+ rows = min(self._minimumVisibleRows, self._visibleRowCount())
+ return QSize(super().minimumSizeHint().width(), self._heightForRows(rows))
def sizeHint(self) -> QSize:
count = self._visibleRowCount()
if self._maximumVisibleRows is not None:
count = min(count, self._maximumVisibleRows)
- return self._sizeForRows(count).expandedTo(self.minimumSizeHint())
+ return QSize(self._contentWidth(), self._heightForRows(count)).expandedTo(self.minimumSizeHint())