diff --git a/src/qt_gui/game_grid_frame.cpp b/src/qt_gui/game_grid_frame.cpp index 6a42fb1d6..e06fea090 100644 --- a/src/qt_gui/game_grid_frame.cpp +++ b/src/qt_gui/game_grid_frame.cpp @@ -196,14 +196,28 @@ void GameGridFrame::SetGridBackgroundImage(int row, int column) { void GameGridFrame::RefreshGridBackgroundImage() { QPalette palette; if (!backgroundImage.isNull() && Config::getShowBackgroundImage()) { - palette.setBrush(QPalette::Base, - QBrush(backgroundImage.scaled(size(), Qt::IgnoreAspectRatio))); + QSize widgetSize = size(); + QPixmap scaledPixmap = + QPixmap::fromImage(backgroundImage) + .scaled(widgetSize, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); + int x = (widgetSize.width() - scaledPixmap.width()) / 2; + int y = (widgetSize.height() - scaledPixmap.height()) / 2; + QPixmap finalPixmap(widgetSize); + finalPixmap.fill(Qt::transparent); + QPainter painter(&finalPixmap); + painter.drawPixmap(x, y, scaledPixmap); + palette.setBrush(QPalette::Base, QBrush(finalPixmap)); } QColor transparentColor = QColor(135, 206, 235, 40); palette.setColor(QPalette::Highlight, transparentColor); this->setPalette(palette); } +void GameGridFrame::resizeEvent(QResizeEvent* event) { + QTableWidget::resizeEvent(event); + RefreshGridBackgroundImage(); +} + bool GameGridFrame::IsValidCellSelected() { return validCellSelected; } diff --git a/src/qt_gui/game_grid_frame.h b/src/qt_gui/game_grid_frame.h index 370b71dcb..14596f8e1 100644 --- a/src/qt_gui/game_grid_frame.h +++ b/src/qt_gui/game_grid_frame.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include "background_music_player.h" @@ -21,6 +22,7 @@ Q_SIGNALS: public Q_SLOTS: void SetGridBackgroundImage(int row, int column); void RefreshGridBackgroundImage(); + void resizeEvent(QResizeEvent* event); void PlayBackgroundMusic(QString path); void onCurrentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn); diff --git a/src/qt_gui/game_list_frame.cpp b/src/qt_gui/game_list_frame.cpp index 2caae35b0..4c0607571 100644 --- a/src/qt_gui/game_list_frame.cpp +++ b/src/qt_gui/game_list_frame.cpp @@ -200,14 +200,28 @@ void GameListFrame::SetListBackgroundImage(QTableWidgetItem* item) { void GameListFrame::RefreshListBackgroundImage() { QPalette palette; if (!backgroundImage.isNull() && Config::getShowBackgroundImage()) { - palette.setBrush(QPalette::Base, - QBrush(backgroundImage.scaled(size(), Qt::IgnoreAspectRatio))); + QSize widgetSize = size(); + QPixmap scaledPixmap = + QPixmap::fromImage(backgroundImage) + .scaled(widgetSize, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); + int x = (widgetSize.width() - scaledPixmap.width()) / 2; + int y = (widgetSize.height() - scaledPixmap.height()) / 2; + QPixmap finalPixmap(widgetSize); + finalPixmap.fill(Qt::transparent); + QPainter painter(&finalPixmap); + painter.drawPixmap(x, y, scaledPixmap); + palette.setBrush(QPalette::Base, QBrush(finalPixmap)); } QColor transparentColor = QColor(135, 206, 235, 40); palette.setColor(QPalette::Highlight, transparentColor); this->setPalette(palette); } +void GameListFrame::resizeEvent(QResizeEvent* event) { + QTableWidget::resizeEvent(event); + RefreshListBackgroundImage(); +} + void GameListFrame::SortNameAscending(int columnIndex) { std::sort(m_game_info->m_games.begin(), m_game_info->m_games.end(), [columnIndex](const GameInfo& a, const GameInfo& b) { diff --git a/src/qt_gui/game_list_frame.h b/src/qt_gui/game_list_frame.h index b2e5f1e2f..782db6bae 100644 --- a/src/qt_gui/game_list_frame.h +++ b/src/qt_gui/game_list_frame.h @@ -30,6 +30,7 @@ Q_SIGNALS: public Q_SLOTS: void SetListBackgroundImage(QTableWidgetItem* item); void RefreshListBackgroundImage(); + void resizeEvent(QResizeEvent* event); void SortNameAscending(int columnIndex); void SortNameDescending(int columnIndex); void PlayBackgroundMusic(QTableWidgetItem* item);