From 1ee30146e561d8ee7dcd068ca104f6ef7f4cabce Mon Sep 17 00:00:00 2001 From: NinjaCheetah <58050615+NinjaCheetah@users.noreply.github.com> Date: Sun, 11 May 2025 22:21:53 -0400 Subject: [PATCH] Fixed dropdown styling once and for all --- NUSGet.py | 2 ++ modules/core.py | 12 ++++++++++-- resources/style.qss | 3 +-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/NUSGet.py b/NUSGet.py index d6a19f4..9ea9079 100644 --- a/NUSGet.py +++ b/NUSGet.py @@ -122,6 +122,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): list_view = QListView() list_view.setMouseTracking(True) self.ui.console_select_dropdown.setView(list_view) + dropdown_delegate = ComboBoxItemDelegate() + self.ui.console_select_dropdown.setItemDelegate(dropdown_delegate) self.ui.console_select_dropdown.currentIndexChanged.connect(self.selected_console_changed) # Title tree loading code. Now powered by Models:tm: wii_model = NUSGetTreeModel(wii_database, root_name="Wii Titles") diff --git a/modules/core.py b/modules/core.py index f510d6c..e579075 100644 --- a/modules/core.py +++ b/modules/core.py @@ -8,7 +8,15 @@ import requests from dataclasses import dataclass from typing import List -from PySide6.QtCore import Qt as _Qt +from PySide6.QtCore import Qt, QSize +from PySide6.QtWidgets import QStyledItemDelegate, QSizePolicy + + +# This is required to make the dropdown look correct with the custom styling. A little fuzzy on the why, but it has to +# do with how Qt handles rendering the dropdown items. The sizing has to be overridden so that they don't overlap. +class ComboBoxItemDelegate(QStyledItemDelegate): + def sizeHint(self, option, index): + return QSize(option.rect.width(), 33) @dataclass @@ -42,7 +50,7 @@ class BatchResults: def connect_label_to_checkbox(label, checkbox): def toggle_checkbox(event): - if checkbox.isEnabled() and event.button() == _Qt.LeftButton: + if checkbox.isEnabled() and event.button() == Qt.LeftButton: checkbox.toggle() label.mousePressEvent = toggle_checkbox diff --git a/resources/style.qss b/resources/style.qss index 8bb8130..ea0542d 100644 --- a/resources/style.qss +++ b/resources/style.qss @@ -196,6 +196,7 @@ QPushButton:disabled { QComboBox { background-color: transparent; + combobox-popup: 0; border: 1px solid rgba(70, 70, 70, 1); border-radius: 8px; padding: 6px 10px; @@ -233,8 +234,6 @@ QComboBox QAbstractItemView { background-color: #2b2b2b; border: 1px solid #444444; border-radius: 8px; - selection-background-color: #1a73e8; - selection-color: white; padding: 4px; outline: none; }