forked from aronamao/PySide2-Collapsible-Widget
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.py
More file actions
79 lines (60 loc) · 2.84 KB
/
example.py
File metadata and controls
79 lines (60 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from PySide6 import QtWidgets
from PySide6.QtGui import QPalette, QColor
from Container import Container
import sys
# Create a custom MainWindow class that inherits from QtWidgets.QMainWindow
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
# Create a central widget for the main window
self.central_widget = QtWidgets.QWidget()
self.setCentralWidget(self.central_widget)
# Create a vertical layout and assign it to the central widget
self.layout = QtWidgets.QVBoxLayout(self.central_widget)
# Create an instance of the Container class and add it to the layout
self.container = Container("Group", color_background=True)
self.layout.addWidget(self.container)
# Create a content layout for the Container and add a button to it
content_layout = QtWidgets.QGridLayout(self.container.contentWidget)
content_layout.addWidget(QtWidgets.QPushButton("Button"))
# Create a toggle button and connect it to the container's toggle method
self.toggle_button = QtWidgets.QPushButton("Toggle Container")
self.toggle_button.clicked.connect(self.toggle_container)
self.layout.addWidget(self.toggle_button)
# Add a vertical spacer at the bottom
self.layout.addStretch(1)
def toggle_container(self):
"""Toggle the visibility of the container."""
if self.container.contentWidget.isVisible():
self.container.collapse()
else:
self.container.expand()
# Define a function to apply a dark theme to the application.
def apply_dark_theme(app):
"""Apply dark theme to the application."""
# Create a QPalette object.
palette = QPalette()
palette.setColor(QPalette.Window, QColor(53, 53, 53))
palette.setColor(QPalette.WindowText, QColor(255, 255, 255))
palette.setColor(QPalette.Base, QColor(25, 25, 25))
palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
palette.setColor(QPalette.ToolTipBase, QColor(255, 255, 255))
palette.setColor(QPalette.ToolTipText, QColor(255, 255, 255))
palette.setColor(QPalette.Text, QColor(255, 255, 255))
palette.setColor(QPalette.Button, QColor(53, 53, 53))
palette.setColor(QPalette.ButtonText, QColor(255, 255, 255))
palette.setColor(QPalette.BrightText, QColor(255, 0, 0))
palette.setColor(QPalette.Highlight, QColor(142, 45, 197).lighter())
palette.setColor(QPalette.HighlightedText, QColor(0, 0, 0))
app.setPalette(palette)
if __name__ == "__main__":
# Create a QApplication object.
app = QtWidgets.QApplication(sys.argv)
# Apply the dark theme to the application.
apply_dark_theme(app)
# Create a MainWindow object.
main_window = MainWindow()
# Show the main window.
main_window.show()
# Run the application event loop.
sys.exit(app.exec())