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())
|
||||
Reference in New Issue
Block a user