Closed immiProgrammer closed 1 year ago
i am using QAbstractTableModel with QSortFilterProxyModel
this is showing when i enable dpi scale
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
when i not enable dpi scale all TableItemDelegate same sized
Try tableView.resizeRowsToContents()
when you update the data of table
when i use QTableView this bug is not showing:
i use this line of code:
self.thread.finished.connect(lambda: [self.table_view.resizeRowToContents(row) for row in range(self.proxy_model.rowCount())])
the results is:
https://github.com/zhiyiYo/PyQt-Fluent-Widgets/assets/101139501/39b15b4c-45bb-4aa8-87f9-abfcc5d607ba
i use also this line of code: self.thread.finished.connect(lambda: self.table_view.resizeRowsToContents())
even then show same results thats show in above video
Could you provide the minimum code to reproduce this problem.
this is minimum code and full understanding code:
from PyQt5.QtCore import Qt, QSortFilterProxyModel, QAbstractTableModel
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget
import pandas as pd
from qfluentwidgets import TableView, LineEdit
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
#* Filtering Data
class CustomFilterProxyModel(QSortFilterProxyModel):
def __init__(self, parent=None):
super().__init__(parent)
self.filter_text = ""
def setFilterText(self, text):
self.filter_text = text
self.invalidateFilter()
def filterAcceptsRow(self, source_row, source_parent):
index0 = self.sourceModel().index(source_row, self.filterKeyColumn(), source_parent)
value0 = self.sourceModel().data(index0, Qt.DisplayRole)
self.filter_text = self.filter_text.lower()
if self.filter_text in value0.lower():
return True
return False
#* QAbstractTableModel For Pandas
class PandasTableModel(QAbstractTableModel):
def __init__(self, path:str):
super().__init__()
self._data = pd.read_csv(path)
self._data.drop_duplicates(subset="Name", keep='first', inplace=True)
def rowCount(self, parent=None):
return self._data.shape[0]
def columnCount(self, parent=None):
return self._data.shape[1]
def data(self, index, role=Qt.DisplayRole):
if index.isValid() and role in [Qt.DisplayRole, Qt.EditRole]:
return str(self._data.iloc[index.row(), index.column()])
def headerData(self, section, orientation, role=Qt.DisplayRole):
if role == Qt.DisplayRole:
if orientation == Qt.Horizontal:
return str(self._data.columns[section])
elif orientation == Qt.Vertical:
return str(self._data.index[section]+1)
return super().headerData(section, orientation, role)
#* Manage TableView and LineEdit
class TableViewManager:
def __init__(self, model) -> None:
self.model = model
self.proxy_model = CustomFilterProxyModel()
self.proxy_model.setSourceModel(self.model)
self.table_view = TableView()
self.table_view.setModel(self.proxy_model)
def setLineEdit(self, lineE:LineEdit):
lineE.textChanged.connect(self.proxy_model.setFilterText)
lineE.returnPressed.connect(lambda:self.proxy_model.setFilterText(self.lineedit.text()))
if __name__ == '__main__':
app = QApplication([])
app.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings)
tablemanager = TableViewManager(PandasTableModel(r"C:\Users\self\Desktop\products 1.csv"))
tablemanager.proxy_model.setFilterKeyColumn(0)
table_view = tablemanager.table_view
#* Create Custom LineEdit and connect into table
line_edit = LineEdit()
tablemanager.setLineEdit(line_edit)
# Create a layout for the main window
layout = QVBoxLayout()
layout.addWidget(line_edit)
layout.addWidget(table_view)
# Create a main window widget and set the layout
window = QWidget()
window.setLayout(layout)
window.show()
window.setMinimumSize(700, 500)
app.exec()
when i comment showEvent Function in 'qfluentwidgets\components\widgets\table_view.py' all items has same size but same not changed
Please provide the CSV file
Please provide the CSV file products 1 - Copy.csv
Please provide the CSV file
Are u face this issue?
table_view.verticalHeader().setDefaultSectionSize(40)
or
table_view.verticalHeader().setMinimumSectionSize(40)