zhiyiYo / PyQt-Fluent-Widgets

A fluent design widgets library based on C++ Qt/PyQt/PySide. Make Qt Great Again.
https://qfluentwidgets.com
GNU General Public License v3.0
4.98k stars 464 forks source link

[Bug]: TableWidget doesn't word-wrap with verticalHeader set to 'Resize to Contents' #910

Closed PyFlat-JR closed 3 days ago

PyFlat-JR commented 1 week ago

What happened?

grafik

I have a QTableWidget with the horizontalHeader on stretch. If there is a text in one of the cells that is longer than the width of the header, the text is cut off. With QTableWidget the problem can be solved by changing the SectionResizeMode of the verticalHeader to QHeaderView.ResizeToContents. WordWrap then simply increases the height of the cell. With TableWidget, however, the text remains truncated and the height of the cell does not change.

Operation System

Windows 10 22H2

Python Version

3.11.2 64-bit

PyQt/PySide Version

PySide 6.6.3.1

PyQt/PySide-Fluent-Widgets Version

v1.5.8

How to Reproduce?

Create a TableWidget set verticalHeader.SectionResizeMode to QHeaderView.ResizeToContents and add a text to the widget longer than the width of the header section so it should do WordWrap.

Minimum code

import sys

from PySide6.QtWidgets import (
    QApplication,
    QHBoxLayout,
    QHeaderView,
    QMainWindow,
    QTableWidget,
    QTableWidgetItem,
    QWidget,
)
from qfluentwidgets import TableWidget

class MyWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Two TableWidgets Example")

        central_widget = QWidget(self)
        self.setCentralWidget(central_widget)

        layout = QHBoxLayout(central_widget)

        table1 = QTableWidget()
        table1.setColumnCount(1)
        table1.setRowCount(1)
        table1.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)

        table2 = TableWidget()
        table2.setColumnCount(1)
        table2.setRowCount(1)
        table2.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)

        data1 = "test test test test test"

        item1 = QTableWidgetItem(data1)
        item2 = QTableWidgetItem(data1)
        table1.setItem(0, 0, item1)
        table2.setItem(0, 0, item2)

        layout.addWidget(table1)
        layout.addWidget(table2)

        central_widget.setLayout(layout)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MyWindow()
    window.show()
    sys.exit(app.exec())
zhiyiYo commented 3 days ago

You need to set the wrap mode of Tablewidget

PyFlat-JR commented 2 days ago

But wordWrap() is True by default so setting it to True doesnt change anything. Or is there a different setting to set the wrap behaviour?