working on headers outside of viewport

This commit is contained in:
billypom on debian 2024-09-17 19:56:00 -04:00
parent 240f449f0a
commit e8c27c782e
2 changed files with 35 additions and 30 deletions

View File

@ -96,8 +96,8 @@ class MusicTable(QTableView):
None, None,
] ]
# Header stuff... # Header stuff...
# header = ResizableHeaderView(Qt.Horizontal, self) header = ResizableHeaderView(Qt.Horizontal, self)
# self.setHorizontalHeader(header) self.setHorizontalHeader(header)
# hide the id column # hide the id column
self.hideColumn(0) self.hideColumn(0)
# db names of headers # db names of headers
@ -106,12 +106,12 @@ class MusicTable(QTableView):
self.songChanged = None self.songChanged = None
self.selected_song_filepath = "" self.selected_song_filepath = ""
self.current_song_filepath = "" self.current_song_filepath = ""
table_view_column_widths = str(self.config["table"]["column_widths"]).split(",") # table_view_column_widths = str(self.config["table"]["column_widths"]).split(",")
for i in range(self.model.columnCount() - 1): # for i in range(self.model.columnCount() - 1):
self.setColumnWidth(i, int(table_view_column_widths[i])) # self.setColumnWidth(i, int(table_view_column_widths[i]))
self.horizontalHeader().setStretchLastSection(True) # self.horizontalHeader().setStretchLastSection(True)
self.horizontalHeader().setSectionResizeMode(QHeaderView.Interactive) # self.horizontalHeader().setSectionResizeMode(QHeaderView.Interactive)
self.horizontalHeader().setCascadingSectionResizes(True) # self.horizontalHeader().setCascadingSectionResizes(True)
# CONNECTIONS # CONNECTIONS
self.clicked.connect(self.set_selected_song_filepath) self.clicked.connect(self.set_selected_song_filepath)
self.doubleClicked.connect(self.set_current_song_filepath) self.doubleClicked.connect(self.set_current_song_filepath)
@ -119,33 +119,38 @@ class MusicTable(QTableView):
self.deleteKey.connect(self.delete_songs) self.deleteKey.connect(self.delete_songs)
self.model.dataChanged.connect(self.on_cell_data_changed) # editing cells self.model.dataChanged.connect(self.on_cell_data_changed) # editing cells
self.model.layoutChanged.connect(self.restore_scroll_position) 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 # Final actions
self.load_music_table() self.load_music_table()
self.setup_keyboard_shortcuts() self.setup_keyboard_shortcuts()
def resizeEvent(self, e: typing.Optional[QResizeEvent]) -> None: def resizeEvent(self, e: typing.Optional[QResizeEvent]) -> None:
print(f"QTableView size: {self.size().width()}") print(f"QTableView width: {self.size().width()}")
if e is None: if e is None:
raise Exception raise Exception
super().resizeEvent(e) super().resizeEvent(e)
self.setMaximumSize(self.size().width(), self.size().height())
def header_was_resized(self, logicalIndex, oldSize, newSize): def header_was_resized(self, logicalIndex, oldSize, newSize):
# super().sectionResized(logicalIndex, oldSize, newSize) self.adjust_section_sizes(logicalIndex, oldSize, newSize)
self.adjust_section_sizes()
def adjust_section_sizes(self): def adjust_section_sizes(self, logicalIndex, oldSize, newSize):
column_count = self.model.columnCount() header_width = 0
total_width = 0 current_width = self.size().width()
for i in range(self.model.columnCount()): for i in range(self.model.columnCount()):
total_width += self.columnWidth(i) header_width += self.columnWidth(i)
print(f"total_width = {total_width}") 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)
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
menu = QMenu(self) menu = QMenu(self)
add_to_playlist_action = QAction("Add to playlist", self) add_to_playlist_action = QAction("Add to playlist", self)
add_to_playlist_action.triggered.connect(self.add_selected_files_to_playlist) add_to_playlist_action.triggered.connect(self.add_selected_files_to_playlist)
@ -172,7 +177,8 @@ class MusicTable(QTableView):
menu.addAction(delete_action) menu.addAction(delete_action)
# show # show
self.set_selected_song_filepath() self.set_selected_song_filepath()
menu.exec_(a0.globalPos()) if a0 is not None:
menu.exec_(a0.globalPos())
def show_id3_tags_debug_menu(self): def show_id3_tags_debug_menu(self):
"""Shows ID3 tags for a specific .mp3 file""" """Shows ID3 tags for a specific .mp3 file"""

View File

@ -1,5 +1,5 @@
from PyQt5.QtWidgets import QHeaderView from PyQt5.QtWidgets import QHeaderView
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
import configparser import configparser
@ -11,11 +11,13 @@ class ResizableHeaderView(QHeaderView):
self.parent = parent self.parent = parent
# FIXME: last column needs to not leave the screen when other columns become big... # FIXME: last column needs to not leave the screen when other columns become big...
# howwww # howwww
table_view_column_widths = str(self.config["table"]["column_widths"]).split(",")
for i in range(parent.model.columnCount() - 1): # table_view_column_widths = str(self.config["table"]["column_widths"]).split(",")
self.setColumnWidth(i, int(table_view_column_widths[i])) # for i in range(self.parent.model.columnCount() - 1):
self.setStretchLastSection(True) # self.setColumnWidth(i, int(table_view_column_widths[i]))
# self.setStretchLastSection(True)
self.setSectionResizeMode(QHeaderView.Interactive) self.setSectionResizeMode(QHeaderView.Interactive)
self.setCascadingSectionResizes(True)
def resizeEvent(self, e): def resizeEvent(self, e):
super().resizeEvent(e) super().resizeEvent(e)
@ -29,9 +31,6 @@ class ResizableHeaderView(QHeaderView):
column_count = self.count() column_count = self.count()
total_width = 0 total_width = 0
for i in range(self.parent.model.columnCount()): for i in range(column_count):
total_width += self.parent.model.columnWidth(i) total_width += self.sectionSize(i)
print(f"total_width = {total_width}") print(f"total_width = {total_width}")
if not self.default_column_proportions:
self.default_column_proportions = [1] * column_count