diff --git a/app/musicmuster.py b/app/musicmuster.py index 1fa982c..d82ae76 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -219,6 +219,8 @@ class Window(QMainWindow, Ui_MainWindow): lambda: self.tabPlaylist.currentWidget().scroll_current_to_top()) self.hdrNextTrack.clicked.connect( lambda: self.tabPlaylist.currentWidget().scroll_next_to_top()) + self.tabPlaylist.currentChanged.connect( + lambda: self.tabPlaylist.currentWidget().tab_visible()) self.tabPlaylist.tabCloseRequested.connect(self.close_tab) self.txtSearch.returnPressed.connect(self.search_playlist_return) @@ -968,7 +970,7 @@ class DbDialog(QDialog): """ Subclassed QDialog to manage track selection - If get_one_track is True, return after first track selection + If get_one_track is True, return after first track selection with that track in ui.track. Otherwise, allow multiple tracks to be added to the playlist. """ diff --git a/app/playlists.py b/app/playlists.py index 118c9bb..524350b 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -13,6 +13,7 @@ from PyQt5.QtCore import ( QObject, QSize, Qt, + QTimer, ) from PyQt5.QtGui import ( QBrush, @@ -151,7 +152,6 @@ class PlaylistTab(QTableWidget): item: QTableWidgetItem = QTableWidgetItem() self.setHorizontalHeaderItem(idx, item) self.horizontalHeader().setMinimumSectionSize(0) - self._set_column_widths(session) # Set column headings sorted by idx self.setHorizontalHeaderLabels( [a.heading for a in list(sorted(columns.values(), @@ -748,6 +748,13 @@ class PlaylistTab(QTableWidget): scroll_to: QTableWidgetItem = self.item(0, 0) self.scrollToItem(scroll_to, QAbstractItemView.PositionAtTop) + # Set widths + self._set_column_widths(session) + + # Needed to wrap notes column correctly - add to event queue so + # that it's processed after list populated + QTimer.singleShot(0, self.tab_visible) + # We possibly don't need to save the playlist here, but row # numbers may have changed during population, and it's cheap to do # self.save_playlist(session) @@ -973,6 +980,13 @@ class PlaylistTab(QTableWidget): with Session() as session: self._set_next(session, row) + def tab_visible(self) -> None: + """Called when tab becomes visible""" + + # Set row heights + self.resizeRowsToContents() + self.setColumnWidth(len(columns) - 1, 0) + def update_display(self, session, clear_selection: bool = True) -> None: """ Set row colours, fonts, etc @@ -1017,9 +1031,6 @@ class PlaylistTab(QTableWidget): # Get note colour note_colour = NoteColours.get_colour(session, note_text) - # Set row height - self.resizeRowToContents(row) - # Get track if there is one track_id = self._get_row_track_id(row) track = None @@ -1151,6 +1162,10 @@ class PlaylistTab(QTableWidget): self._set_row_bold(row) continue + # Set row heights + self.resizeRowsToContents() + self.setColumnWidth(len(columns) - 1, 0) + # Have we had a section start but not end? if section_start_plr is not None: self._update_note_text( @@ -1224,6 +1239,10 @@ class PlaylistTab(QTableWidget): with Session() as session: for column_name, data in columns.items(): idx = data.idx + if idx == len(columns) - 1: + # Don't set width of last column as it's set to + # stretch + continue width = self.columnWidth(idx) attribute_name = f"playlist_{column_name}_col_width" record = Settings.get_int_settings(session, attribute_name) @@ -1702,6 +1721,11 @@ class PlaylistTab(QTableWidget): for column_name, data in columns.items(): idx = data.idx + if idx == len(columns) - 1: + # Set width of last column to zero as it's set to stretch + print(f"Set {column_name} to zero width, {self.playlist_id=}") + self.setColumnWidth(idx, 0) + continue attr_name = f"playlist_{column_name}_col_width" record: Settings = Settings.get_int_settings(session, attr_name) if record and record.f_int is not None: