@@ -274,10 +274,16 @@ def eventFilter(self, source, event):
274
274
source .setProperty ("class" ,f"button{ source .property ('class' ).split ()[1 ]} hover" )
275
275
source .style ().unpolish (source )
276
276
source .style ().polish (source )
277
+ for child in source .findChildren (QLabel ):
278
+ child .style ().unpolish (child )
279
+ child .style ().polish (child )
277
280
elif event .type ()== QtCore .QEvent .Type .Leave and isinstance (source ,QPushButton ):
278
281
source .setProperty ("class" ,f"button{ source .property ('class' ).split ()[1 ]} " )
279
282
source .style ().unpolish (source )
280
283
source .style ().polish (source )
284
+ for child in source .findChildren (QLabel ):
285
+ child .style ().unpolish (child )
286
+ child .style ().polish (child )
281
287
return super (MainWindow ,self ).eventFilter (source ,event )
282
288
283
289
def keyPressEvent (self ,event ):
@@ -291,10 +297,10 @@ def keyPressEvent(self, event):
291
297
self .navigate_focus (- 1 )
292
298
event .accept ()# Mark event as handled
293
299
elif event .key ()== Qt .Key .Key_Down :
294
- self .navigate_focus (self .button_row )
300
+ self .navigate_focus (self .button_row )# Move down by one row
295
301
event .accept ()# Mark event as handled
296
302
elif event .key ()== Qt .Key .Key_Up :
297
- self .navigate_focus (- self .button_row )
303
+ self .navigate_focus (- self .button_row )# Move up by one row
298
304
event .accept ()# Mark event as handled
299
305
elif event .key ()in (Qt .Key .Key_Return ,Qt .Key .Key_Enter ,Qt .Key .Key_Space ):
300
306
# Trigger click on the focused button
@@ -303,7 +309,7 @@ def keyPressEvent(self, event):
303
309
event .accept ()# Mark event as handled
304
310
else :
305
311
super (MainWindow ,self ).keyPressEvent (event )
306
-
312
+
307
313
def navigate_focus (self ,step ):
308
314
"""Navigate button focus by step."""
309
315
if not self .buttons_list :
@@ -314,30 +320,52 @@ def navigate_focus(self, step):
314
320
# If no button is currently focused, start with the appropriate first button
315
321
if self .current_focus_index < 0 or self .current_focus_index >= total_buttons :
316
322
if step > 0 :
317
- # When pressing right arrow with no selection, select the first button
323
+ # When pressing rightor down arrow with no selection, select the first button
318
324
new_index = 0
319
325
elif step < 0 :
320
- # When pressing left arrow with no selection, select the last button
326
+ # When pressing leftor up arrow with no selection, select the last button
321
327
new_index = total_buttons - 1
322
328
else :
323
- #For other keys with no selection, default to first button
329
+ #Default to first button
324
330
new_index = 0
325
331
else :
326
332
# Normal navigation with existing selection
327
333
current = self .current_focus_index
328
334
329
- # Simple navigation with wrapping
330
335
if step == 1 :# Right
331
336
new_index = (current + 1 )% total_buttons
332
337
elif step == - 1 :# Left
333
338
new_index = (current - 1 )% total_buttons
334
- elif step == self .button_row :# Down
335
- new_index = (current + self .button_row )% total_buttons
336
- elif step == - self .button_row :# Up
337
- new_index = (current - self .button_row )% total_buttons
339
+ elif step == self .button_row or step == - self .button_row :# Up/Down - vertical movement
340
+ # Calculate the current row and column
341
+ current_row = current // self .button_row
342
+ current_col = current % self .button_row
343
+
344
+ # Determine total rows
345
+ total_rows = (total_buttons + self .button_row - 1 )// self .button_row
346
+
347
+ if step == self .button_row :# Down
348
+ # Move to next row, same column
349
+ new_row = (current_row + 1 )% total_rows
350
+ else :# Up
351
+ # Move to previous row, same column
352
+ new_row = (current_row - 1 )% total_rows
353
+
354
+ # Calculate new index
355
+ new_index = new_row * self .button_row + current_col
356
+
357
+ # If we've moved to a partial row and the column is beyond its bounds
358
+ if new_index >= total_buttons :
359
+ if step == self .button_row :
360
+ # When moving down to an out-of-bounds position, wrap to first row
361
+ new_index = current_col
362
+ else :
363
+ # When moving up to an out-of-bounds position, use last valid button
364
+ new_index = total_buttons - 1
338
365
else :
339
366
new_index = current # No change
340
-
367
+
368
+ new_index = max (0 ,min (new_index ,total_buttons - 1 ))
341
369
self .set_focused_button (new_index )
342
370
343
371
def set_focused_button (self ,index ):