trying resize headers

This commit is contained in:
tsi-billypom 2024-09-13 11:33:05 -04:00
parent 50919cddb8
commit eb0eda1dda
4 changed files with 12 additions and 31 deletions

View File

@ -7,9 +7,11 @@ from PyQt5.QtGui import (
QKeySequence, QKeySequence,
QDragEnterEvent, QDragEnterEvent,
QDropEvent, QDropEvent,
QResizeEvent,
) )
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAction, QAction,
QHeaderView,
QMenu, QMenu,
QTableView, QTableView,
QShortcut, QShortcut,
@ -43,6 +45,7 @@ import logging
import configparser import configparser
import os import os
import shutil import shutil
import typing
class MusicTable(QTableView): class MusicTable(QTableView):
@ -106,6 +109,10 @@ class MusicTable(QTableView):
self.load_music_table() self.load_music_table()
self.setup_keyboard_shortcuts() self.setup_keyboard_shortcuts()
def resizeEvent(self, e: typing.Optional[QResizeEvent]) -> None:
assert e is not None
return super().resizeEvent(e)
def contextMenuEvent(self, a0): def contextMenuEvent(self, a0):
"""Right-click context menu for rows in Music Table""" """Right-click context menu for rows in Music Table"""
assert a0 is not None assert a0 is not None

View File

@ -249,8 +249,8 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
for i in range(self.tableView.model.columnCount()): for i in range(self.tableView.model.columnCount()):
self.tableView.setColumnWidth(i, int(table_view_column_widths[i])) self.tableView.setColumnWidth(i, int(table_view_column_widths[i]))
# dont extend last column past table view border # dont extend last column past table view border
self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) # self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.tableView.horizontalHeader().setStretchLastSection(False) # self.tableView.horizontalHeader().setStretchLastSection(False)
def reload_config(self) -> None: def reload_config(self) -> None:
"""does what it says""" """does what it says"""

12
ui.py
View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ui.ui' # Form implementation generated from reading ui file 'ui.ui'
# #
# Created by: PyQt5 UI code generator 5.15.11 # Created by: PyQt5 UI code generator 5.15.9
# #
# WARNING: Any manual changes made to this file will be lost when pyuic5 is # WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing. # run again. Do not edit this file unless you know what you are doing.
@ -106,22 +106,14 @@ class Ui_MainWindow(object):
self.playlistTreeView.setObjectName("playlistTreeView") self.playlistTreeView.setObjectName("playlistTreeView")
self.hLayoutMusicTable.addWidget(self.playlistTreeView) self.hLayoutMusicTable.addWidget(self.playlistTreeView)
self.tableView = MusicTable(self.centralwidget) self.tableView = MusicTable(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(1)
sizePolicy.setHeightForWidth(self.tableView.sizePolicy().hasHeightForWidth())
self.tableView.setSizePolicy(sizePolicy)
self.tableView.setMaximumSize(QtCore.QSize(32000, 32000))
self.tableView.setAcceptDrops(True) self.tableView.setAcceptDrops(True)
self.tableView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.tableView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.tableView.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
self.tableView.setEditTriggers(QtWidgets.QAbstractItemView.AnyKeyPressed|QtWidgets.QAbstractItemView.EditKeyPressed) self.tableView.setEditTriggers(QtWidgets.QAbstractItemView.AnyKeyPressed|QtWidgets.QAbstractItemView.EditKeyPressed)
self.tableView.setAlternatingRowColors(True) self.tableView.setAlternatingRowColors(True)
self.tableView.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) self.tableView.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.tableView.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) self.tableView.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.tableView.setSortingEnabled(True) self.tableView.setSortingEnabled(True)
self.tableView.setObjectName("tableView") self.tableView.setObjectName("tableView")
self.tableView.horizontalHeader().setCascadingSectionResizes(True)
self.tableView.horizontalHeader().setStretchLastSection(True) self.tableView.horizontalHeader().setStretchLastSection(True)
self.tableView.verticalHeader().setVisible(False) self.tableView.verticalHeader().setVisible(False)
self.hLayoutMusicTable.addWidget(self.tableView) self.hLayoutMusicTable.addWidget(self.tableView)
@ -166,7 +158,7 @@ class Ui_MainWindow(object):
self.verticalLayout_3.setStretch(2, 1) self.verticalLayout_3.setStretch(2, 1)
MainWindow.setCentralWidget(self.centralwidget) MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1152, 41)) self.menubar.setGeometry(QtCore.QRect(0, 0, 1152, 21))
self.menubar.setObjectName("menubar") self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar) self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile") self.menuFile.setObjectName("menuFile")

20
ui.ui
View File

@ -177,27 +177,12 @@
</item> </item>
<item> <item>
<widget class="MusicTable" name="tableView"> <widget class="MusicTable" name="tableView">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>32000</width>
<height>32000</height>
</size>
</property>
<property name="acceptDrops"> <property name="acceptDrops">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="horizontalScrollBarPolicy"> <property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum> <enum>Qt::ScrollBarAlwaysOff</enum>
</property> </property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="editTriggers"> <property name="editTriggers">
<set>QAbstractItemView::AnyKeyPressed|QAbstractItemView::EditKeyPressed</set> <set>QAbstractItemView::AnyKeyPressed|QAbstractItemView::EditKeyPressed</set>
</property> </property>
@ -213,9 +198,6 @@
<property name="sortingEnabled"> <property name="sortingEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderStretchLastSection"> <attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool> <bool>true</bool>
</attribute> </attribute>
@ -299,7 +281,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1152</width> <width>1152</width>
<height>41</height> <height>21</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">