Background image sized correctly (#2451)

This commit is contained in:
DanielSvoboda 2025-02-15 13:19:33 -03:00 committed by GitHub
parent 2b9a8e5605
commit e042710eaa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 4 deletions

View file

@ -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) {