Skip to content

Commit

Permalink
qtui: Work around Qt 6 resetting column widths during StyleChange
Browse files Browse the repository at this point in the history
  • Loading branch information
jlindgren90 committed Mar 20, 2024
1 parent 9e2b83a commit f02b4ea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/qtui/playlist_header.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
#include <libaudqt/libaudqt.h>

static const char * const s_col_keys[] = {
"number", "title", "artist", "year", "album",
"album-artist", "track", "genre", "queued", "length",
"path", "filename", "custom", "bitrate", "comment",
"publisher", "catalog-number", "disc"};
"number", "title", "artist", "year", "album",
"album-artist", "track", "genre", "queued", "length",
"path", "filename", "custom", "bitrate", "comment",
"publisher", "catalog-number", "disc"};

static const int s_default_widths[] = {
25, // entry number
Expand Down Expand Up @@ -262,6 +262,23 @@ void PlaylistHeader::contextMenuEvent(QContextMenuEvent * event)
menu->popup(event->globalPos());
}

bool PlaylistHeader::event(QEvent * event)
{
// Work around Qt 6 resetting column widths during StyleChange
// (happens at least with 6.6.2, did not happen with Qt 5.x)
m_inStyleChange = (event->type() == QEvent::StyleChange);

bool ret = QHeaderView::event(event);

if (m_inStyleChange)
{
updateColumns();
m_inStyleChange = false;
}

return ret;
}

void PlaylistHeader::updateColumns()
{
m_inUpdate = true;
Expand Down Expand Up @@ -330,7 +347,7 @@ void PlaylistHeader::sectionClicked(int logicalIndex)
void PlaylistHeader::sectionMoved(int logicalIndex, int oldVisualIndex,
int newVisualIndex)
{
if (m_inUpdate)
if (m_inUpdate || m_inStyleChange)
return;

int old_pos = oldVisualIndex - 1;
Expand All @@ -356,7 +373,7 @@ void PlaylistHeader::sectionMoved(int logicalIndex, int oldVisualIndex,
void PlaylistHeader::sectionResized(int logicalIndex, int /*oldSize*/,
int newSize)
{
if (m_inUpdate)
if (m_inUpdate || m_inStyleChange)
return;

int col = logicalIndex - 1;
Expand Down
2 changes: 2 additions & 0 deletions src/qtui/playlist_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ class PlaylistHeader : public QHeaderView
private:
PlaylistWidget * m_playlist;
bool m_inUpdate = false;
bool m_inStyleChange = false;
int m_lastCol = -1;

void sectionClicked(int logicalIndex);
void sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex);
void sectionResized(int logicalIndex, int /*oldSize*/, int newSize);

void contextMenuEvent(QContextMenuEvent * event);
bool event(QEvent * event);

void updateStyle();

Expand Down

0 comments on commit f02b4ea

Please sign in to comment.