add splitter
This commit is contained in:
@@ -1,7 +1,78 @@
|
||||
import PySide6.QtCore
|
||||
import sys
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
|
||||
QPushButton, QLabel, QSplitter, QStackedWidget
|
||||
)
|
||||
from PySide6.QtCore import Qt, Slot
|
||||
from PySide6.QtGui import QPalette, QColor
|
||||
|
||||
# Prints PySide6 version
|
||||
print(PySide6.__version__)
|
||||
class PlaceholderWidget(QWidget):
|
||||
"""A custom widget to display a colored background with centered text."""
|
||||
def __init__(self, text: str, color: str, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setAutoFillBackground(True)
|
||||
self.set_color(color)
|
||||
|
||||
# Prints the Qt version used to compile PySide6
|
||||
print(PySide6.QtCore.__version__)
|
||||
self.label = QLabel(text)
|
||||
self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
font = self.label.font()
|
||||
font.setPointSize(24)
|
||||
self.label.setFont(font)
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.addWidget(self.label)
|
||||
self.setLayout(layout)
|
||||
|
||||
def set_text(self, text: str):
|
||||
self.label.setText(text)
|
||||
|
||||
def set_color(self, color: str):
|
||||
palette = self.palette()
|
||||
palette.setColor(QPalette.ColorRole.Window, QColor(color))
|
||||
self.setPalette(palette)
|
||||
|
||||
def set_text_color(self, color: str):
|
||||
palette = self.label.palette()
|
||||
palette.setColor(QPalette.ColorRole.WindowText, QColor(color))
|
||||
self.label.setPalette(palette)
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("Bejcownik 0.1.0")
|
||||
self.resize(1920, 1080)
|
||||
|
||||
# Main layout
|
||||
central_widget = QWidget()
|
||||
main_layout = QHBoxLayout(central_widget)
|
||||
self.setCentralWidget(central_widget)
|
||||
|
||||
pink_widget = PlaceholderWidget("Pink", "#8A004C" , central_widget)
|
||||
pink_widget.set_text_color("#FFFFFF")
|
||||
|
||||
gray_widget = PlaceholderWidget("Gray", "#808080", central_widget)
|
||||
gray_widget.set_text_color("#FFFFFF")
|
||||
|
||||
purple_widget = PlaceholderWidget("Purple", "#800080", central_widget)
|
||||
purple_widget.set_text_color("#FFFFFF")
|
||||
|
||||
green_widget = PlaceholderWidget("Green", "#008000", central_widget)
|
||||
green_widget.set_text_color("#FFFFFF")
|
||||
|
||||
self.view_splitter = QSplitter(Qt.Orientation.Horizontal)
|
||||
self.view_splitter.addWidget(pink_widget)
|
||||
self.view_splitter.addWidget(gray_widget)
|
||||
self.view_splitter.addWidget(purple_widget)
|
||||
|
||||
self.view_splitter.setSizes([0, 1, 0]) # Początkowy podział na pół
|
||||
main_layout.addWidget(self.view_splitter)
|
||||
main_layout.addWidget(green_widget)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
sys.exit(app.exec())
|
||||
59
collaps.py
Normal file
59
collaps.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication, QWidget, QVBoxLayout, QToolButton, QFrame, QLabel, QSizePolicy
|
||||
)
|
||||
from PySide6.QtCore import Qt
|
||||
|
||||
|
||||
class CollapsiblePanel(QWidget):
|
||||
def __init__(self, title="", parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.toggle_button = QToolButton(text=title, checkable=True, checked=False)
|
||||
self.toggle_button.setStyleSheet("QToolButton { border: none; }")
|
||||
self.toggle_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
|
||||
self.toggle_button.setArrowType(Qt.RightArrow)
|
||||
self.toggle_button.clicked.connect(self.on_toggle)
|
||||
|
||||
self.content_area = QFrame()
|
||||
self.content_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
||||
self.content_area.setMaximumHeight(0) # startowo schowane
|
||||
|
||||
# Layout panelu
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.addWidget(self.toggle_button)
|
||||
layout.addWidget(self.content_area)
|
||||
|
||||
def on_toggle(self, checked):
|
||||
if checked:
|
||||
self.toggle_button.setArrowType(Qt.DownArrow)
|
||||
self.content_area.setMaximumHeight(16777215) # odblokuj wysokość
|
||||
else:
|
||||
self.toggle_button.setArrowType(Qt.RightArrow)
|
||||
self.content_area.setMaximumHeight(0) # schowaj
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication([])
|
||||
|
||||
main = QWidget()
|
||||
layout = QVBoxLayout(main)
|
||||
|
||||
# Panel 1
|
||||
panel1 = CollapsiblePanel("Opcje")
|
||||
panel1.content_area.setLayout(QVBoxLayout())
|
||||
panel1.content_area.layout().addWidget(QLabel("Opcja A"))
|
||||
panel1.content_area.layout().addWidget(QLabel("Opcja B"))
|
||||
|
||||
# Panel 2
|
||||
panel2 = CollapsiblePanel("Zaawansowane")
|
||||
panel2.content_area.setLayout(QVBoxLayout())
|
||||
panel2.content_area.layout().addWidget(QLabel("Parametr 1"))
|
||||
panel2.content_area.layout().addWidget(QLabel("Parametr 2"))
|
||||
|
||||
layout.addWidget(panel1)
|
||||
layout.addWidget(panel2)
|
||||
layout.addStretch()
|
||||
|
||||
main.show()
|
||||
app.exec()
|
||||
75
collaps2.py
Normal file
75
collaps2.py
Normal file
@@ -0,0 +1,75 @@
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication, QWidget, QVBoxLayout, QToolButton, QFrame, QLabel, QSizePolicy
|
||||
)
|
||||
from PySide6.QtCore import Qt, QSize
|
||||
def hline():
|
||||
line = QFrame()
|
||||
line.setFrameShape(QFrame.HLine)
|
||||
line.setFrameShadow(QFrame.Plain) # prosta, 1-pikselowa linia
|
||||
line.setLineWidth(1)
|
||||
return line
|
||||
|
||||
|
||||
class CollapsiblePanel(QWidget):
|
||||
def __init__(self, title="", content_margins=(12, 10, 12, 12), parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
# Nagłówek
|
||||
self.toggle_button = QToolButton(text=title, checkable=True, checked=False)
|
||||
self.toggle_button.setStyleSheet("QToolButton { border: none; font-weight: 600;}")
|
||||
self.toggle_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
|
||||
self.toggle_button.setArrowType(Qt.RightArrow)
|
||||
self.toggle_button.setIconSize(QSize(36, 36)) # domyślnie 16x16
|
||||
|
||||
self.toggle_button.clicked.connect(self.on_toggle)
|
||||
|
||||
# Obszar zawartości
|
||||
self.content_area = QFrame()
|
||||
self.content_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
||||
self.content_area.setMaximumHeight(0) # startowo schowane
|
||||
|
||||
# Wewnętrzny layout na Twoje widgety + PADDING (marginesy)
|
||||
self.body_layout = QVBoxLayout(self.content_area)
|
||||
l, t, r, b = content_margins
|
||||
self.body_layout.setContentsMargins(l, t, r, b)
|
||||
self.body_layout.setSpacing(6)
|
||||
|
||||
# Layout zewnętrzny panelu (bez dodatkowych marginesów)
|
||||
root = QVBoxLayout(self)
|
||||
root.setContentsMargins(0, 0, 0, 0)
|
||||
root.setSpacing(0)
|
||||
root.addWidget(self.toggle_button)
|
||||
root.addWidget(self.content_area)
|
||||
|
||||
def on_toggle(self, checked):
|
||||
if checked:
|
||||
self.toggle_button.setArrowType(Qt.DownArrow)
|
||||
self.content_area.setMaximumHeight(16777215)
|
||||
else:
|
||||
self.toggle_button.setArrowType(Qt.RightArrow)
|
||||
self.content_area.setMaximumHeight(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication([])
|
||||
|
||||
main = QWidget()
|
||||
layout = QVBoxLayout(main)
|
||||
# layout.setContentsMargins(50, 12, 12, 12) # marginesy całego widoku
|
||||
layout.setSpacing(8) # odstęp m.in. na linię
|
||||
|
||||
panel1 = CollapsiblePanel("Opcje", content_margins=(50, 10, 12, 12))
|
||||
panel1.body_layout.addWidget(QLabel("Opcja A"))
|
||||
panel1.body_layout.addWidget(QLabel("Opcja B"))
|
||||
|
||||
panel2 = CollapsiblePanel("Zaawansowane", content_margins=(16, 12, 16, 16))
|
||||
panel2.body_layout.addWidget(QLabel("Parametr 1"))
|
||||
panel2.body_layout.addWidget(QLabel("Parametr 2"))
|
||||
|
||||
layout.addWidget(panel1)
|
||||
layout.addWidget(hline()) # separator
|
||||
layout.addWidget(panel2)
|
||||
layout.addStretch()
|
||||
|
||||
main.show()
|
||||
app.exec()
|
||||
Reference in New Issue
Block a user