MCPcopy Create free account
hub / github.com/MCSLTeam/MCSL2 / ServerWindowTitleBar

Class ServerWindowTitleBar

MCSL2Lib/ServerControllers/windowCreator.py:593–738  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

591
592
593class ServerWindowTitleBar(FluentTitleBar):
594 def __init__(self, parent):
595 super().__init__(parent)
596 self.setFixedHeight(40)
597 self.macOSLeftColumn = None # 保存macOS左侧列控件
598 self.hBoxLayout.removeWidget(self.minBtn)
599 self.hBoxLayout.removeWidget(self.maxBtn)
600 self.hBoxLayout.removeWidget(self.closeBtn)
601
602 # add window icon
603 self.placeholderLabel = QLabel(self)
604 self.placeholderLabel.setFixedSize(18, 18)
605 self.hBoxLayout.insertWidget(0, self.placeholderLabel, 0, Qt.AlignRight | Qt.AlignVCenter)
606
607 self.iconLabel = QLabel(self)
608 self.iconLabel.setFixedSize(18, 18)
609 self.hBoxLayout.insertWidget(1, self.iconLabel, 0, Qt.AlignLeft | Qt.AlignVCenter)
610 self.window().windowIconChanged.connect(self.setIcon)
611
612 # add title label
613 self.titleLabel = QLabel(self)
614 self.hBoxLayout.insertWidget(2, self.titleLabel, 0, Qt.AlignLeft | Qt.AlignVCenter)
615 self.titleLabel.setObjectName("titleLabel")
616 self.window().windowTitleChanged.connect(self.setTitle)
617
618 self.vBoxLayout = QVBoxLayout()
619 self.buttonLayout = QHBoxLayout()
620 self.buttonLayout.setSpacing(0)
621 self.buttonLayout.setContentsMargins(0, 0, 0, 0)
622 self.buttonLayout.setAlignment(Qt.AlignTop)
623 self.buttonLayout.addWidget(self.minBtn)
624 self.buttonLayout.addWidget(self.maxBtn)
625 self.buttonLayout.addWidget(self.closeBtn)
626 self.vBoxLayout.addLayout(self.buttonLayout)
627 self.vBoxLayout.addStretch(1)
628 self.hBoxLayout.addLayout(self.vBoxLayout, 0)
629 self.fixMacOSTitleBar()
630 self.setQss()
631
632 # 在window上安装事件过滤器以捕获全屏状态变化
633 self.window().installEventFilter(self)
634
635 def fixMacOSTitleBar(self):
636 """在macOS上为titleBar添加占位符"""
637 if system().lower() != "darwin":
638 return
639
640 leftColumn = QWidget(self)
641 leftColumn.setFixedWidth(58)
642 leftColumn.setStyleSheet("background-color: transparent;")
643 self.hBoxLayout.insertWidget(0, leftColumn, 0)
644 self.macOSLeftColumn = leftColumn
645
646 def eventFilter(self, obj: QObject, event: QEvent) -> bool:
647 """监听窗口的事件"""
648 if obj is self.window() and event.type() == QEvent.WindowStateChange:
649 # 检查是否在 macOS 上
650 if system().lower() == "darwin":

Callers 1

initWindowMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected