Improve table column sizes

This commit is contained in:
Fabian 2021-11-17 03:48:39 +01:00
parent c3cde56eb8
commit 30c4035eff
2 changed files with 7 additions and 6 deletions

View File

@ -2,6 +2,8 @@ from PySide2 import QtCore, QtGui, QtWidgets
from datetime import datetime from datetime import datetime
from PySide2.QtWidgets import QHeaderView
from data import Tasks from data import Tasks
@ -37,7 +39,10 @@ class Report(QtWidgets.QDialog):
self.tableWidget.cellChanged.connect(self.cell_changed) self.tableWidget.cellChanged.connect(self.cell_changed)
self.tableWidget.setItemDelegateForColumn(0, Report.TaskItemCompleter(self._tasks, self)) self.tableWidget.setItemDelegateForColumn(0, Report.TaskItemCompleter(self._tasks, self))
self.header = QtWidgets.QHeaderView(QtCore.Qt.Orientation.Horizontal) self.header = QtWidgets.QHeaderView(QtCore.Qt.Orientation.Horizontal)
self.header.setMinimumSectionSize(1)
self.header.setSectionResizeMode(QHeaderView.ResizeToContents)
self.tableWidget.setHorizontalHeader(self.header) self.tableWidget.setHorizontalHeader(self.header)
self.header.setSectionResizeMode(self.header.logicalIndex(0), QHeaderView.Stretch)
self.previous_button = QtWidgets.QPushButton() self.previous_button = QtWidgets.QPushButton()
self.previous_button.setText("Previous") self.previous_button.setText("Previous")
@ -112,13 +117,8 @@ class Report(QtWidgets.QDialog):
item1.setFlags(item0.flags() & QtCore.Qt.ItemIsEnabled) item1.setFlags(item0.flags() & QtCore.Qt.ItemIsEnabled)
self._changing_items = False self._changing_items = False
self.tableWidget.resizeColumnsToContents() self.tableWidget.resizeColumnToContents(0)
min_width = 0
for i in range(3):
min_width += self.header.sectionSize(i)
self.tableWidget.setMinimumWidth(min_width * 1.33)
self.header.setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
if self.tableWidget.rowCount() > 4: if self.tableWidget.rowCount() > 4:
if hasattr(self.tableWidget, "screen"): if hasattr(self.tableWidget, "screen"):
screen_height = self.tableWidget.screen().size().height() screen_height = self.tableWidget.screen().size().height()

View File

@ -9,6 +9,7 @@ class TaskEdit(QtWidgets.QDialog):
self.tableView = QtWidgets.QTableView() self.tableView = QtWidgets.QTableView()
self.tableView.setModel(self.list) self.tableView.setModel(self.list)
self.tableView.horizontalHeader().setStretchLastSection(True)
self.tableView.horizontalHeader().hide() self.tableView.horizontalHeader().hide()
self.tableView.verticalHeader().hide() self.tableView.verticalHeader().hide()