Closed DancingSnow0517 closed 1 year ago
我复现不出来呀,代码咋写的
原先setRowCount(50)再setRowCount(30)再回到setRowCount(50) 好像就是先减少再增多就这样了
我这的需求就是根据数据的长度来设置多少行
再测试了下,原本60行,setRowCount(10)之后,第十行之后的高度都变小了
明天再试试吧,先去睡了😴
会这样嘛 我得好像不会 我也是根据内容调整高度
再测试了下,原本60行,setRowCount(10)之后,第十行之后的高度都变小了
设置行数为 10 之后后面还有新的数据吗?
我这边也是这种情况 初始化设置row的数量(比如5个)后,新增的row(超过5)的高度不够,在5个范围内的高度正常
只能在更新数据的时候手动调高度(?
def tableUpdateData(self, currentData):
for index, each in enumerate(currentData):
for eachColumn in range(0, 5):
self.bottomLeftGachaTable.setItem(index, eachColumn, QTableWidgetItem())
self.bottomLeftGachaTable.setRowHeight(index, 50)
self.bottomLeftGachaTable.item(index, eachColumn).setText(each[eachColumn])
有更新 rowCount 吗
更新过
def __headerRightGachaTypeComboboxChanged(self):
currentTableData = self.completedOriginalTableData[
GACHATYPE_TO_CODE[self.headerRightGachaTypeCombobox.currentText()]]
self.bottomLeftGachaTable.setRowCount(len(currentTableData))
self.tableUpdateData(currentTableData)
我试着把 table_view/demo.py 的初始行数设为 5,接着扩充到 20,也没被压缩高度
你们用的是 gallery 界面写的 TableFrame
吗
from qfluentwidgets import TableWidget
self.bottomLeftGachaTable = TableWidget()
试一下用 demo 来复现吧,不然光看代码也看不出问题所在
复现出来了,右边的按钮多按几下就这样了
# coding: utf-8
import random
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QTableWidgetItem, QWidget, QHBoxLayout
from qfluentwidgets import TableWidget, PushButton
class Demo(QWidget):
def __init__(self):
super().__init__()
# setTheme(Theme.DARK)
self.hBoxLayout = QHBoxLayout(self)
self.tableView = TableWidget(self)
self.button = PushButton("按钮", self)
self.button.clicked.connect(self.on_button_click)
self.tableView.setWordWrap(False)
self.tableView.setRowCount(5)
self.tableView.setColumnCount(5)
self.songInfos = [
['かばん', 'aiko', 'かばん', '2004', '5:04'],
['爱你', '王心凌', '爱你', '2004', '3:39'],
['星のない世界', 'aiko', '星のない世界/横顔', '2007', '5:30'],
['横顔', 'aiko', '星のない世界/横顔', '2007', '5:06'],
['秘密', 'aiko', '秘密', '2008', '6:27'],
['シアワセ', 'aiko', '秘密', '2008', '5:25'],
['二人', 'aiko', '二人', '2008', '5:00'],
['スパークル', 'RADWIMPS', '君の名は。', '2016', '8:54'],
['なんでもないや', 'RADWIMPS', '君の名は。', '2016', '3:16'],
['前前前世', 'RADWIMPS', '人間開花', '2016', '4:35'],
['恋をしたのは', 'aiko', '恋をしたのは', '2016', '6:02'],
['夏バテ', 'aiko', '恋をしたのは', '2016', '4:41'],
['もっと', 'aiko', 'もっと', '2016', '4:50'],
['問題集', 'aiko', 'もっと', '2016', '4:18'],
['半袖', 'aiko', 'もっと', '2016', '5:50'],
['ひねくれ', '鎖那', 'Hush a by little girl', '2017', '3:54'],
['シュテルン', '鎖那', 'Hush a by little girl', '2017', '3:16'],
['愛は勝手', 'aiko', '湿った夏の始まり', '2018', '5:31'],
['ドライブモード', 'aiko', '湿った夏の始まり', '2018', '3:37'],
['うん。', 'aiko', '湿った夏の始まり', '2018', '5:48'],
['キラキラ', 'aikoの詩。', '2019', '5:08', 'aiko'],
['恋のスーパーボール', 'aiko', 'aikoの詩。', '2019', '4:31'],
['磁石', 'aiko', 'どうしたって伝えられないから', '2021', '4:24'],
['食べた愛', 'aiko', '食べた愛/あたしたち', '2021', '5:17'],
['列車', 'aiko', '食べた愛/あたしたち', '2021', '4:18'],
['花の塔', 'さユり', '花の塔', '2022', '4:35'],
['夏恋のライフ', 'aiko', '夏恋のライフ', '2022', '5:03'],
['あかときリロード', 'aiko', 'あかときリロード', '2023', '4:04'],
['荒れた唇は恋を失くす', 'aiko', '今の二人をお互いが見てる', '2023', '4:07'],
['ワンツースリー', 'aiko', '今の二人をお互いが見てる', '2023', '4:47'],
]
for i, songInfo in enumerate(self.songInfos):
if i == 5:
break
for j in range(5):
self.tableView.setItem(i, j, QTableWidgetItem(songInfo[j]))
self.tableView.verticalHeader().hide()
self.tableView.setHorizontalHeaderLabels(['标题', '艺人', '专辑', '年份', '时长'])
self.tableView.resizeColumnsToContents()
# self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
# self.tableView.setSortingEnabled(True)
self.setStyleSheet("Demo{background: rgb(249, 249, 249)} ")
self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
self.hBoxLayout.addWidget(self.tableView)
self.hBoxLayout.addWidget(self.button)
self.resize(625, 700)
def on_button_click(self):
rows = random.randint(5, len(self.songInfos))
self.tableView.setRowCount(rows)
for i in range(rows):
for j in range(5):
self.tableView.setItem(i, j, QTableWidgetItem(self.songInfos[i][j]))
if __name__ == "__main__":
# enable dpi scale
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
app = QApplication(sys.argv)
w = Demo()
w.show()
app.exec()
在槽函数里面加上 self.tableView.resizeRowsToContents()
就行了
啊,确实
Describe the bug 一个表格,但是在某一行后,高度变小了
Environment
To Reproduce Steps to reproduce the behavior(you can use gif to demonstrate the problem):
Code
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.