Refactor QComboBox styling to use native system arrow for improved compatibility and fix rendering issues

This commit is contained in:
2025-08-18 09:54:00 +02:00
parent b6662d81da
commit 46fb5e176b
+41 -62
View File
@@ -954,19 +954,7 @@ class SettingsDialog(QtWidgets.QDialog):
subcontrol-origin: padding; subcontrol-origin: padding;
subcontrol-position: center right; subcontrol-position: center right;
}} }}
QComboBox::down-arrow {{ /* Removed custom down-arrow to use native system arrow (fix for missing/rectangle glyphs) */
image: none;
width: 0px;
height: 0px;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 6px solid {colors['foreground']};
margin: 0px;
padding: 0px;
}}
QComboBox::down-arrow:hover {{
border-top-color: {colors['accent']};
}}
QComboBox QAbstractItemView {{ QComboBox QAbstractItemView {{
background-color: {colors['input_bg']}; background-color: {colors['input_bg']};
border: 1px solid {colors['border']}; border: 1px solid {colors['border']};
@@ -1180,19 +1168,7 @@ class SettingsDialog(QtWidgets.QDialog):
subcontrol-origin: padding; subcontrol-origin: padding;
subcontrol-position: center right; subcontrol-position: center right;
}} }}
QComboBox::down-arrow {{ /* Removed custom down-arrow to use native system arrow (fix for missing/rectangle glyphs) */
image: none;
width: 0px;
height: 0px;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 6px solid {colors['foreground']};
margin: 0px;
padding: 0px;
}}
QComboBox::down-arrow:hover {{
border-top-color: {colors['accent']};
}}
QComboBox QAbstractItemView {{ QComboBox QAbstractItemView {{
background-color: {colors['input_bg']}; background-color: {colors['input_bg']};
border: 1px solid {colors['border']}; border: 1px solid {colors['border']};
@@ -2286,13 +2262,15 @@ class MainWindow(QtWidgets.QMainWindow):
config_path = os.path.join(CONFIG_DIR, 'window_config.json') config_path = os.path.join(CONFIG_DIR, 'window_config.json')
# Get current geometry # Use frameGeometry to capture actual on-screen top-left (accounts for title bar)
frame_geo = self.frameGeometry()
geometry_data = { geometry_data = {
'x': self.x(), 'x': frame_geo.x(),
'y': self.y(), 'y': frame_geo.y(),
'width': self.width(), 'width': self.width(), # client width
'height': self.height(), 'height': self.height(), # client height
'maximized': self.isMaximized() 'maximized': self.isMaximized(),
'qt_geometry': bytes(self.saveGeometry()).hex() # serialized QByteArray
} }
# Validate geometry data before saving - only prevent extremely invalid values # Validate geometry data before saving - only prevent extremely invalid values
@@ -2362,11 +2340,30 @@ class MainWindow(QtWidgets.QMainWindow):
screen_width = screen.width() screen_width = screen.width()
screen_height = screen.height() screen_height = screen.height()
# Use the exact saved position and dimensions - no adjustments # First try Qt native restore if available
x = geometry_data['x'] if 'qt_geometry' in geometry_data:
y = geometry_data['y'] try:
width = geometry_data['width'] geo_bytes = bytes.fromhex(geometry_data['qt_geometry'])
height = geometry_data['height'] if self.restoreGeometry(QtCore.QByteArray(geo_bytes)):
logger.debug("Restored geometry via Qt restoreGeometry")
# Ensure move matches saved frame position (some WM shift). Adjust if off by <=10px
saved_x, saved_y = geometry_data['x'], geometry_data['y']
current_frame = self.frameGeometry()
dx = saved_x - current_frame.x()
dy = saved_y - current_frame.y()
if abs(dx) > 2 or abs(dy) > 2:
self.move(saved_x, saved_y)
# Continue to restore other settings then return
else:
logger.debug("Qt restoreGeometry failed, falling back to manual restore")
except Exception as e:
logger.debug(f"Qt geometry restore error, fallback manual: {e}")
# Manual fallback if needed (or to overwrite size only)
x = geometry_data.get('x', self.x())
y = geometry_data.get('y', self.y())
width = geometry_data.get('width', max(640, self.width()))
height = geometry_data.get('height', max(720, self.height()))
# Only ensure the saved dimensions meet actual minimum requirements # Only ensure the saved dimensions meet actual minimum requirements
# but preserve the exact position # but preserve the exact position
@@ -2386,8 +2383,9 @@ class MainWindow(QtWidgets.QMainWindow):
if y > screen_height - 10: # Too far down (only if less than 10px visible) if y > screen_height - 10: # Too far down (only if less than 10px visible)
y = screen_height - 10 y = screen_height - 10
# Apply geometry immediately # Apply position and size separately to reduce WM adjustments
self.setGeometry(x, y, width, height) self.move(x, y)
self.resize(width, height)
# Log the exact values being applied for debugging # Log the exact values being applied for debugging
logger.debug(f"Applying geometry: x={x}, y={y}, width={width}, height={height}") logger.debug(f"Applying geometry: x={x}, y={y}, width={width}, height={height}")
@@ -2395,14 +2393,14 @@ class MainWindow(QtWidgets.QMainWindow):
logger.debug(f"Screen dimensions: {screen_width}x{screen_height}") logger.debug(f"Screen dimensions: {screen_width}x{screen_height}")
# Apply geometry again with a small delay to override any system adjustments # Apply geometry again with a small delay to override any system adjustments
QtCore.QTimer.singleShot(50, lambda: self.setGeometry(x, y, width, height)) QtCore.QTimer.singleShot(50, lambda: (self.move(x, y), self.resize(width, height)))
# Restore maximized state if applicable # Restore maximized state if applicable
if geometry_data.get('maximized', False): if geometry_data.get('maximized', False):
self.showMaximized() self.showMaximized()
else: else:
# Ensure we're not maximized and apply the geometry one more time # Ensure we're not maximized and apply the geometry one more time
QtCore.QTimer.singleShot(100, lambda: self.setGeometry(x, y, width, height)) QtCore.QTimer.singleShot(100, lambda: (self.move(x, y), self.resize(width, height)))
# Restore update interval if saved # Restore update interval if saved
saved_interval = config.get('update_interval') saved_interval = config.get('update_interval')
@@ -3002,14 +3000,7 @@ class MainWindow(QtWidgets.QMainWindow):
subcontrol-origin: padding; subcontrol-origin: padding;
subcontrol-position: center right; subcontrol-position: center right;
}} }}
QComboBox::down-arrow {{ /* Removed custom down-arrow to use native system arrow (fix for missing/rectangle glyphs) */
/* Use native arrow; prior triangle via borders rendered as rectangles on some systems */
width: 12px;
height: 12px;
}}
QComboBox::down-arrow:hover {{
/* Keep default hover */
}}
QComboBox QAbstractItemView {{ QComboBox QAbstractItemView {{
background-color: {colors['input_bg']}; background-color: {colors['input_bg']};
border: 1px solid {colors['border']}; border: 1px solid {colors['border']};
@@ -3124,19 +3115,7 @@ class MainWindow(QtWidgets.QMainWindow):
subcontrol-origin: padding; subcontrol-origin: padding;
subcontrol-position: center right; subcontrol-position: center right;
}} }}
QComboBox::down-arrow {{ /* Removed custom down-arrow to use native system arrow (fix for missing/rectangle glyphs) */
image: none;
width: 0px;
height: 0px;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 6px solid {colors['foreground']};
margin: 0px;
padding: 0px;
}}
QComboBox::down-arrow:hover {{
border-top-color: {colors['accent']};
}}
QComboBox QAbstractItemView {{ QComboBox QAbstractItemView {{
background-color: {colors['input_bg']}; background-color: {colors['input_bg']};
border: 1px solid {colors['border']}; border: 1px solid {colors['border']};