Fixed some crashs that occurred when clicking on the tab bar, but not on a tab.

This commit is contained in:
The Wobbler 2025-01-29 16:25:57 +01:00
parent 1decb3adea
commit 8a3d5a5b15

View file

@ -26,6 +26,9 @@ class PlaylistTabBar(QTabBar):
self.tab_widget.setCurrentIndex(index) self.tab_widget.setCurrentIndex(index)
def on_click(self, index): def on_click(self, index):
if index == -1: # do nothing if no tab was clicked
return
playlist_view = self.tab_widget.widget(index) playlist_view = self.tab_widget.widget(index)
playlist = playlist_view.playlist playlist = playlist_view.playlist
@ -38,10 +41,16 @@ class PlaylistTabBar(QTabBar):
self.app.player.start_playlist(playlist) self.app.player.start_playlist(playlist)
def contextMenuEvent(self, event: QContextMenuEvent, title=None): def contextMenuEvent(self, event: QContextMenuEvent, title=None):
# get title by self.tabAt() if the event is called from PyQt, else its executed from the tab title and getting
# the index by tabAt() wouldn't be possible
if title is None: if title is None:
pos = event.pos() pos = event.pos()
index = self.tabAt(pos) index = self.tabAt(pos)
if index == -1: # when no tab was clicked, do nothing
return
title = self.tabButton(index, QTabBar.ButtonPosition.RightSide) title = self.tabButton(index, QTabBar.ButtonPosition.RightSide)
self.context_menu.exec(event.globalPos(), title) self.context_menu.exec(event.globalPos(), title)