Update built-in QtWidgets styles

Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
Loren Eteval
2025-06-23 23:50:47 +08:00
parent 3574007063
commit 5611965df0
+32
View File
@@ -31,6 +31,8 @@ from PySide6.QtWidgets import *
import functools
from typing import Union
__all__ = [
'moveToCenter',
'AppQCheckBox',
@@ -372,7 +374,12 @@ class AppQMenu(QTranslatable, SupportConnectedCallback, QMenu):
@staticmethod
def getStyleSheet(color):
return (
f'QMenu {{'
f' padding: 6px;'
f'}}'
f''
f'QMenu::item {{'
f' padding: 6px 12px;'
f' background-color: solid;'
f'}}'
f''
@@ -481,6 +488,7 @@ class AppQTableWidget(SupportConnectedCallback, QTableWidget):
super().__init__(*args, **kwargs)
self.setWordWrap(False)
self.setAlternatingRowColors(True)
@property
def selectedIndex(self):
@@ -572,6 +580,30 @@ class AppQToolBar(QTranslatable, QToolBar):
self.setStyleSheet(self.getStyleSheet())
self.actionTriggered.connect(self.showMenuBelow)
@QtCore.Slot(AppQAction)
def showMenuBelow(self, action: AppQAction):
def toolBarWidgetForAction() -> Union[QWidget | None]:
# Walk through the toolbar to find the widget for the action
for child in self.children():
if hasattr(child, 'defaultAction'):
# PySide6.QtWidgets.QMenu.defaultAction
assert isinstance(child, QWidget)
if child.defaultAction() == action:
return child
return None
button = toolBarWidgetForAction()
if button is not None:
menu = action._menu
if isinstance(menu, AppQMenu):
menu.exec(button.mapToGlobal(button.rect().bottomLeft()))
@staticmethod
def getStyleSheet():
return f'QToolBar {{ spacing: 5px; }}'