header resizing working - sort of
This commit is contained in:
parent
e8c27c782e
commit
ec9f93add3
@ -95,9 +95,9 @@ class MusicTable(QTableView):
|
||||
"TDRC",
|
||||
None,
|
||||
]
|
||||
# Header stuff...
|
||||
header = ResizableHeaderView(Qt.Horizontal, self)
|
||||
self.setHorizontalHeader(header)
|
||||
#
|
||||
# header = ResizableHeaderView(Qt.Horizontal, self)
|
||||
# self.setHorizontalHeader(header)
|
||||
# hide the id column
|
||||
self.hideColumn(0)
|
||||
# db names of headers
|
||||
@ -106,11 +106,12 @@ class MusicTable(QTableView):
|
||||
self.songChanged = None
|
||||
self.selected_song_filepath = ""
|
||||
self.current_song_filepath = ""
|
||||
# table_view_column_widths = str(self.config["table"]["column_widths"]).split(",")
|
||||
# for i in range(self.model.columnCount() - 1):
|
||||
# self.setColumnWidth(i, int(table_view_column_widths[i]))
|
||||
# self.horizontalHeader().setStretchLastSection(True)
|
||||
# self.horizontalHeader().setSectionResizeMode(QHeaderView.Interactive)
|
||||
|
||||
table_view_column_widths = str(self.config["table"]["column_widths"]).split(",")
|
||||
for i in range(self.model.columnCount() - 1):
|
||||
self.setColumnWidth(i, int(table_view_column_widths[i]))
|
||||
self.horizontalHeader().setStretchLastSection(True)
|
||||
self.horizontalHeader().setSectionResizeMode(QHeaderView.Interactive)
|
||||
# self.horizontalHeader().setCascadingSectionResizes(True)
|
||||
# CONNECTIONS
|
||||
self.clicked.connect(self.set_selected_song_filepath)
|
||||
@ -119,35 +120,41 @@ class MusicTable(QTableView):
|
||||
self.deleteKey.connect(self.delete_songs)
|
||||
self.model.dataChanged.connect(self.on_cell_data_changed) # editing cells
|
||||
self.model.layoutChanged.connect(self.restore_scroll_position)
|
||||
# self.horizontalHeader().sectionResized.connect(self.header_was_resized)
|
||||
self.horizontalHeader().sectionResized.connect(self.header_was_resized)
|
||||
# Final actions
|
||||
self.load_music_table()
|
||||
self.setup_keyboard_shortcuts()
|
||||
|
||||
def resizeEvent(self, e: typing.Optional[QResizeEvent]) -> None:
|
||||
print(f"QTableView width: {self.size().width()}")
|
||||
"""Do something when the QTableView is resized"""
|
||||
if e is None:
|
||||
raise Exception
|
||||
super().resizeEvent(e)
|
||||
|
||||
def header_was_resized(self, logicalIndex, oldSize, newSize):
|
||||
self.adjust_section_sizes(logicalIndex, oldSize, newSize)
|
||||
"""Handles keeping headers inside the viewport"""
|
||||
# https://stackoverflow.com/questions/46775438/how-to-limit-qheaderview-size-when-resizing-sections
|
||||
col_count = self.model.columnCount()
|
||||
qtableview_width = self.size().width()
|
||||
sum_of_cols = self.horizontalHeader().length()
|
||||
|
||||
def adjust_section_sizes(self, logicalIndex, oldSize, newSize):
|
||||
header_width = 0
|
||||
current_width = self.size().width()
|
||||
|
||||
for i in range(self.model.columnCount()):
|
||||
header_width += self.columnWidth(i)
|
||||
if header_width > current_width:
|
||||
# we pushing headers too far
|
||||
newSize = oldSize
|
||||
print("NOOO")
|
||||
print(f"total_width = {header_width}")
|
||||
print(f"logical index = {logicalIndex}")
|
||||
print(f"old size = {oldSize}")
|
||||
print(f"new size = {newSize}")
|
||||
# super().sectionResized(logicalIndex, oldSize, newSize)
|
||||
if sum != qtableview_width:
|
||||
# if not the last header
|
||||
if logicalIndex < col_count:
|
||||
next_header_size = self.horizontalHeader().sectionSize(logicalIndex + 1)
|
||||
# If it should shrink
|
||||
if next_header_size > (sum_of_cols - qtableview_width):
|
||||
# shrink it
|
||||
self.horizontalHeader().resizeSection(
|
||||
logicalIndex + 1,
|
||||
next_header_size - (sum_of_cols - qtableview_width),
|
||||
)
|
||||
else:
|
||||
# block the resize
|
||||
self.horizontalHeader().resizeSection(logicalIndex, oldSize)
|
||||
# else:
|
||||
# if newSize > self.horizontalHeader().minimumSectionSize():
|
||||
# self.horizontalHeader().resizeSection(logicalIndex, oldSize)
|
||||
|
||||
def contextMenuEvent(self, a0):
|
||||
"""Right-click context menu for rows in Music Table"""
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
from PyQt5.QtWidgets import QHeaderView
|
||||
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
|
||||
import configparser
|
||||
|
||||
|
||||
class ResizableHeaderView(QHeaderView):
|
||||
def __init__(self, orientation, parent=None):
|
||||
super().__init__(orientation, parent)
|
||||
self.config = configparser.ConfigParser()
|
||||
self.config.read("config.ini")
|
||||
self.parent = parent
|
||||
# FIXME: last column needs to not leave the screen when other columns become big...
|
||||
# howwww
|
||||
|
||||
# table_view_column_widths = str(self.config["table"]["column_widths"]).split(",")
|
||||
# for i in range(self.parent.model.columnCount() - 1):
|
||||
# self.setColumnWidth(i, int(table_view_column_widths[i]))
|
||||
# self.setStretchLastSection(True)
|
||||
self.setSectionResizeMode(QHeaderView.Interactive)
|
||||
self.setCascadingSectionResizes(True)
|
||||
|
||||
def resizeEvent(self, e):
|
||||
super().resizeEvent(e)
|
||||
self.adjust_section_sizes()
|
||||
|
||||
def sectionResized(self, logicalIndex, oldSize, newSize):
|
||||
super().sectionResized(logicalIndex, oldSize, newSize)
|
||||
self.adjust_section_sizes()
|
||||
|
||||
def adjust_section_sizes(self):
|
||||
column_count = self.count()
|
||||
total_width = 0
|
||||
|
||||
for i in range(column_count):
|
||||
total_width += self.sectionSize(i)
|
||||
print(f"total_width = {total_width}")
|
||||
14
main.py
14
main.py
@ -157,7 +157,6 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.probe: QAudioProbe = QAudioProbe() # Gets audio data
|
||||
self.audio_visualizer: AudioVisualizer = AudioVisualizer(self.player)
|
||||
self.current_volume: int = 50
|
||||
# self.qapp = qapp
|
||||
self.tableView.load_qapp(self)
|
||||
self.albumGraphicsView.load_qapp(self)
|
||||
self.config.read("config.ini")
|
||||
@ -214,6 +213,11 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.actionDeleteLibrary.triggered.connect(self.clear_database)
|
||||
self.actionDeleteDatabase.triggered.connect(self.delete_database)
|
||||
|
||||
# QTableView
|
||||
self.tableView.viewport().installEventFilter(
|
||||
self
|
||||
) # for drag & drop functionality
|
||||
|
||||
## CONNECTIONS
|
||||
# tableView
|
||||
self.tableView.doubleClicked.connect(
|
||||
@ -225,6 +229,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.tableView.playPauseSignal.connect(
|
||||
self.on_play_clicked
|
||||
) # Spacebar toggle play/pause signal
|
||||
self.tableView.handleProgressSignal.connect(self.handle_progress)
|
||||
|
||||
# playlistTreeView
|
||||
self.playlistTreeView.playlistChoiceSignal.connect(
|
||||
@ -237,16 +242,11 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.set_album_art_for_selected_songs
|
||||
)
|
||||
# FIXME: this should delete the album art for the current song - not all selected songs
|
||||
# move functionality to remove album for selected songs to the batch metadata editor
|
||||
# Move functionality to remove album for selected songs to the batch metadata editor
|
||||
# self.albumGraphicsView.albumArtDeleted.connect(
|
||||
# self.delete_album_art_for_selected_songs
|
||||
# )
|
||||
|
||||
self.tableView.viewport().installEventFilter(
|
||||
self
|
||||
) # for drag & drop functionality
|
||||
self.tableView.handleProgressSignal.connect(self.handle_progress)
|
||||
|
||||
def reload_config(self) -> None:
|
||||
"""does what it says"""
|
||||
self.config.read("config.ini")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user