Add more style dynamic change

Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
Loren Eteval
2023-08-17 08:23:34 +08:00
parent d2a74eea74
commit 399120daff
4 changed files with 91 additions and 54 deletions
+18 -38
View File
@@ -31,18 +31,7 @@ class ConnectingProgressBar(Translatable, SupportConnectedCallback, QWidget):
# Create a progress bar widget
self.progressBar = QProgressBar(self)
self.progressBar.setRange(0, 100)
self.progressBar.setStyleSheet(
f'QProgressBar {{'
f' border-radius: 2px;'
f' text-align: center;'
f'}}'
f''
f'QProgressBar::chunk {{'
f' background-color: #43ACED;'
f' width: 10px;'
f' margin: 0.5px;'
f'}}'
)
self.progressBar.setStyleSheet(self.getStyleSheet('#43ACED'))
# create a timer to update the progress bar
self.timer = QtCore.QTimer(self)
@@ -53,6 +42,21 @@ class ConnectingProgressBar(Translatable, SupportConnectedCallback, QWidget):
self.setLayout(self.layout)
@staticmethod
def getStyleSheet(color):
return (
f'QProgressBar {{'
f' border-radius: 2px;'
f' text-align: center;'
f'}}'
f''
f'QProgressBar::chunk {{'
f' background-color: {color};'
f' width: 10px;'
f' margin: 0.5px;'
f'}}'
)
def closeEvent(self, event):
event.ignore()
@@ -60,35 +64,11 @@ class ConnectingProgressBar(Translatable, SupportConnectedCallback, QWidget):
def connectedCallback(self):
self.setWindowIcon(bootstrapIcon('rocket-takeoff-connected-dark.svg'))
self.progressBar.setStyleSheet(
f'QProgressBar {{'
f' border-radius: 2px;'
f' text-align: center;'
f'}}'
f''
f'QProgressBar::chunk {{'
f' background-color: #EB212E;'
f' width: 10px;'
f' margin: 0.5px;'
f'}}'
)
self.progressBar.setStyleSheet(self.getStyleSheet('#F4364C'))
def disconnectedCallback(self):
self.setWindowIcon(bootstrapIcon('rocket-takeoff-window.svg'))
self.progressBar.setStyleSheet(
f'QProgressBar {{'
f' border-radius: 2px;'
f' text-align: center;'
f'}}'
f''
f'QProgressBar::chunk {{'
f' background-color: #43ACED;'
f' width: 10px;'
f' margin: 0.5px;'
f'}}'
)
self.progressBar.setStyleSheet(self.getStyleSheet('#43ACED'))
def retranslate(self):
with StateContext(self):
+3 -3
View File
@@ -1088,7 +1088,7 @@ class NormalServerWidget(Translatable, SupportConnectedCallback, TableWidget):
self.setVerticalHeader(NormalServerVerticalHeader(self))
# Selection
self.setSelectionColor('#008AE1')
self.setSelectionColor('#43ACED')
self.setSelectionBehavior(QTableWidget.SelectionBehavior.SelectRows)
self.setSelectionMode(QTableWidget.SelectionMode.ExtendedSelection)
@@ -1591,12 +1591,12 @@ class NormalServerWidget(Translatable, SupportConnectedCallback, TableWidget):
super().keyPressEvent(event)
def connectedCallback(self):
self.setSelectionColor('#EB212E')
self.setSelectionColor('#F4364C')
# Reactivate with possible color
self.activateItemByIndex(self.activatedItemIndex)
def disconnectedCallback(self):
self.setSelectionColor('#008AE1')
self.setSelectionColor('#43ACED')
# Reactivate with possible color
self.activateItemByIndex(self.activatedItemIndex)
+3 -3
View File
@@ -784,7 +784,7 @@ class EditRoutingTableWidget(Translatable, SupportConnectedCallback, TableWidget
self.setVerticalHeader(EditRoutingTableVerticalHeader(self))
# Selection
self.setSelectionColor('#008AE1')
self.setSelectionColor('#43ACED')
self.setSelectionBehavior(QTableWidget.SelectionBehavior.SelectRows)
self.setSelectionMode(QTableWidget.SelectionMode.ExtendedSelection)
@@ -927,12 +927,12 @@ class EditRoutingTableWidget(Translatable, SupportConnectedCallback, TableWidget
self.setItem(row, column, item)
def connectedCallback(self):
self.setSelectionColor('#EB212E')
self.setSelectionColor('#F4364C')
# Reactivate with possible color
self.activateItemByIndex(routingToIndex(), activate=True)
def disconnectedCallback(self):
self.setSelectionColor('#008AE1')
self.setSelectionColor('#43ACED')
# Reactivate with possible color
self.activateItemByIndex(routingToIndex(), activate=True)
+67 -10
View File
@@ -18,6 +18,7 @@ from PySide6.QtWidgets import (
QListWidget,
QMainWindow,
QMenu,
QMenuBar,
QMessageBox,
QPlainTextEdit,
QPushButton,
@@ -35,33 +36,55 @@ class HeaderView(SupportConnectedCallback, QHeaderView):
self.setSectionsClickable(True)
self.setStyleSheet(
f'QHeaderView::section:hover {{ background-color: #008AE1; }}'
f'QHeaderView::section:hover {{ background-color: #43ACED; }}'
)
def connectedCallback(self):
self.setStyleSheet(
f'QHeaderView::section:hover {{ background-color: #EB212E; }}'
f'QHeaderView::section:hover {{ background-color: #F4364C; }}'
)
def disconnectedCallback(self):
self.setStyleSheet(
f'QHeaderView::section:hover {{ background-color: #008AE1; }}'
f'QHeaderView::section:hover {{ background-color: #43ACED; }}'
)
class ListWidget(QListWidget):
class ListWidget(SupportConnectedCallback, QListWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setSelectionColor('#43ACED')
def setSelectionColor(self, color):
self.setStyleSheet(
f'QListWidget::item:selected {{'
f' background: {color};'
f'}}'
f''
f'QListWidget::item:hover {{'
f' background: {color};'
f'}}'
)
@property
def selectedIndex(self):
return sorted(list(set(index.row() for index in self.selectedIndexes())))
def connectedCallback(self):
self.setSelectionColor('#F4364C')
def disconnectedCallback(self):
self.setSelectionColor('#43ACED')
class MainWindow(Translatable, SupportConnectedCallback, NeedSyncSettings, QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._menuBar = MenuBar(parent=self)
self.setMenuBar(self._menuBar)
def syncSettings(self):
pass
@@ -83,7 +106,7 @@ class MainWindow(Translatable, SupportConnectedCallback, NeedSyncSettings, QMain
self.setWindowTitle(_(self.windowTitle()))
class Menu(Translatable, QMenu):
class Menu(Translatable, SupportConnectedCallback, QMenu):
def __init__(self, *actions, **kwargs):
super().__init__(**kwargs)
@@ -95,21 +118,55 @@ class Menu(Translatable, QMenu):
self.addAction(action)
self.setStyleSheet(
self.setStyleSheet(self.getStyleSheet('#43ACED'))
@staticmethod
def getStyleSheet(color):
return (
f'QMenu::item {{'
f' background-color: solid;'
f'}}'
f''
f'QMenu::item:selected {{'
f' background-color: #43ACED;'
f' background-color: {color};'
f'}}'
)
def connectedCallback(self):
self.setStyleSheet(self.getStyleSheet('#F4364C'))
def disconnectedCallback(self):
self.setStyleSheet(self.getStyleSheet('#43ACED'))
def retranslate(self):
with StateContext(self):
self.setTitle(_(self.title()))
class MenuBar(SupportConnectedCallback, QMenuBar):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setSelectionColor('#43ACED')
def setSelectionColor(self, color):
self.setStyleSheet(
f'QMenuBar::item:selected {{'
f' background: {color};'
f'}}'
f''
f'QMenuBar::item:hover {{'
f' background: {color};'
f'}}'
)
def connectedCallback(self):
self.setSelectionColor('#F4364C')
def disconnectedCallback(self):
self.setSelectionColor('#43ACED')
class MessageBox(Translatable, SupportConnectedCallback, QMessageBox):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -206,12 +263,12 @@ class TableWidget(QTableWidget):
if APP().tray is None:
# Initializing
item.setForeground(QColor('#008AE1'))
item.setForeground(QColor('#43ACED'))
else:
if APP().tray.ConnectAction.isConnected():
item.setForeground(QColor('#EB212E'))
item.setForeground(QColor('#F4364C'))
else:
item.setForeground(QColor('#008AE1'))
item.setForeground(QColor('#43ACED'))
else:
for column in range(self.columnCount()):
item = self.item(int(index), column)