From 4c03348e60e6d269a76281d94b4216022ef55cd2 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 19 May 2018 23:37:32 +0200 Subject: [PATCH] Qt: Restrict trophy manager combo box size --- rpcs3/rpcs3qt/qt_utils.cpp | 22 ++++++++++++++++++++++ rpcs3/rpcs3qt/qt_utils.h | 4 ++++ rpcs3/rpcs3qt/trophy_manager_dialog.cpp | 3 +++ 3 files changed, 29 insertions(+) diff --git a/rpcs3/rpcs3qt/qt_utils.cpp b/rpcs3/rpcs3qt/qt_utils.cpp index 5c6bdd8206..aaf0e862f3 100644 --- a/rpcs3/rpcs3qt/qt_utils.cpp +++ b/rpcs3/rpcs3qt/qt_utils.cpp @@ -2,6 +2,7 @@ #include "qt_utils.h" #include #include +#include #include #include @@ -156,6 +157,27 @@ namespace gui return image.copy(QRect(QPoint(w_max, h_max), QPoint(w_min, h_min))); } + // taken from https://stackoverflow.com/a/30818424/8353754 + // because size policies won't work as expected (see similar bugs in Qt bugtracker) + void resize_combo_box_view(QComboBox* combo) + { + int max_width = 0; + QFontMetrics font_metrics(combo->font()); + + for (int i = 0; i < combo->count(); ++i) + { + max_width = std::max(max_width, font_metrics.width(combo->itemText(i))); + } + + if (combo->view()->minimumWidth() < max_width) + { + // add scrollbar width and margin + max_width += combo->style()->pixelMetric(QStyle::PM_ScrollBarExtent); + max_width += combo->view()->autoScrollMargin(); + combo->view()->setMinimumWidth(max_width); + } + }; + void update_table_item_count(QTableWidget* table) { if (!table) diff --git a/rpcs3/rpcs3qt/qt_utils.h b/rpcs3/rpcs3qt/qt_utils.h index 95b5736714..fb8462732f 100644 --- a/rpcs3/rpcs3qt/qt_utils.h +++ b/rpcs3/rpcs3qt/qt_utils.h @@ -2,6 +2,7 @@ #include "stdafx.h" #include +#include #include #include #include @@ -38,6 +39,9 @@ namespace gui // Returns the part of the image loaded from path that is inside the bounding box of its opaque areas QImage get_opaque_image_area(const QString& path); + // Workaround: resize the dropdown combobox items + void resize_combo_box_view(QComboBox* combo); + // Recalculates a table's item count based on the available visible space and fills it with empty items void update_table_item_count(QTableWidget* table); diff --git a/rpcs3/rpcs3qt/trophy_manager_dialog.cpp b/rpcs3/rpcs3qt/trophy_manager_dialog.cpp index 7e51c22e85..acc3ac3a5e 100644 --- a/rpcs3/rpcs3qt/trophy_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/trophy_manager_dialog.cpp @@ -58,6 +58,7 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr gui_s // Game chooser combo box m_game_combo = new QComboBox(); + m_game_combo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon); // Game progression label m_game_progress = new QLabel(tr("Progress: %1% (%2/%3)").arg(0).arg(0).arg(0)); @@ -148,6 +149,8 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr gui_s m_game_table->setItem(i, GameColumns::GameProgress, new custom_table_widget_item(progress, Qt::UserRole, percentage)); } + gui::utils::resize_combo_box_view(m_game_combo); + m_game_table->setSortingEnabled(true); // Enable sorting only after using setItem calls // Checkboxes to control dialog