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
5.49k stars 523 forks source link

[Bug]: TableView、TableWidget 表格类控件的选择行为失效 #893

Closed wcw-xb closed 2 months ago

wcw-xb commented 4 months ago

What happened?

表格控件TableView TableWidget 默认只能选择一行或者多行,不能选择单个单元格,控件类方法setSelectionBehavior不起作用

Operation System

Windows 11 专业版

Python Version

3.11

PyQt/PySide Version

PySide6 - 6.6.2

PyQt/PySide-Fluent-Widgets Version

PySide6-Fluent-Widgets 1.5.3

How to Reproduce?

bandicam 2024-06-06 18-16-01-572

Minimum code

import sys
from PySide6.QtWidgets import QWidget, QApplication, QTableWidget, QTableWidgetItem, QHBoxLayout
from qfluentwidgets import TableWidget

class MyWidget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.initUI()

    def initUI(self):
        layout = QHBoxLayout(self)

        # 初始化 QTableWidget
        self.table = QTableWidget(self)
        self.table.setColumnCount(3)  # 设置列数
        self.table.setHorizontalHeaderLabels(["col1", "col2", "col3"])  # 设置列标题

        # 初始化 TableWidget
        self.table2 = TableWidget(self)
        self.table2.setColumnCount(3)
        self.table2.setHorizontalHeaderLabels(["col1", "col2", "col3"])

        self.table.setSelectionBehavior(QTableWidget.SelectionBehavior.SelectItems)
        self.table2.setSelectionBehavior(QTableWidget.SelectionBehavior.SelectItems)

        for i in range(4):
            row_position = self.table.rowCount()
            row_position_2 = self.table2.rowCount()
            self.table.insertRow(row_position)
            self.table2.insertRow(row_position_2)
            self.table.setItem(row_position, 0, QTableWidgetItem(f"row{i}"))
            self.table.setItem(row_position, 1, QTableWidgetItem(f"row{i}"))
            self.table.setItem(row_position, 2, QTableWidgetItem(f"row{i}"))
            self.table2.setItem(row_position_2, 0, QTableWidgetItem(f"row{i}"))
            self.table2.setItem(row_position_2, 1, QTableWidgetItem(f"row{i}"))
            self.table2.setItem(row_position_2, 2, QTableWidgetItem(f"row{i}"))

        layout.addWidget(self.table)
        layout.addWidget(self.table2)
        self.setLayout(layout)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MyWidget()
    window.show()
    sys.exit(app.exec())
zhiyiYo commented 2 months ago

默认的代理是直接高亮一整行

zhiyiYo commented 2 months ago

如果需要改变这个行为需要更换代理