You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.6 KiB
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QComboBox, QListView, QHBoxLayout, QVBoxLayout
from UI.Setting.SearchDeviceWidget import DeviceMasterWidget, DeviceSlaveWidget
class CustomBox(QComboBox):
def __init__(self):
super(CustomBox, self).__init__()
self.setCursor(Qt.PointingHandCursor)
self.setView(QListView())
def showPopup(self):
super(CustomBox, self).showPopup()
pop = self.children()[1]
pop.move(pop.x(), pop.y() + 51)
class RemoteConnectSettingWidget(QWidget):
BORDER_WIDTH = 5
def __init__(self):
super().__init__()
# 主布局改为垂直布局包含ComboBox和内容区
self.mainLayout = QVBoxLayout(self)
self.mainLayout.setObjectName("mainLayout")
# 添加模式选择 ComboBox水平居中
self.modeComboBox = QComboBox()
self.modeComboBox.addItem("主站模式")
self.modeComboBox.addItem("从站模式")
self.modeComboBox.setObjectName("setBox")
self.modeComboBox.currentTextChanged.connect(self.switchMode)
# 将ComboBox放在顶部并水平居中
hboxCombo = QHBoxLayout()
hboxCombo.addStretch() # 左侧弹簧
hboxCombo.addWidget(self.modeComboBox)
hboxCombo.addStretch() # 右侧弹簧
self.mainLayout.addLayout(hboxCombo)
self.contentLayout = QHBoxLayout()
# 存储两种模式的Widget
self.deviceMasterWidget = DeviceMasterWidget() # 主站模式
self.deviceSlavrWidget = DeviceSlaveWidget() # 从站模式
# 初始显示主站模式
self.currentWidget = self.deviceMasterWidget
self.contentLayout.addStretch() # 左侧弹簧
self.contentLayout.addWidget(self.currentWidget)
self.contentLayout.addStretch() # 右侧弹簧
self.mainLayout.addLayout(self.contentLayout)
self.mainLayout.addStretch() # 底部弹簧(将内容向上推)
def switchMode(self, mode):
"""切换主站/从站模式"""
# 移除当前Widget
self.contentLayout.removeWidget(self.currentWidget)
self.currentWidget.hide()
# 根据选择显示对应的Widget
if mode == "主站模式":
self.currentWidget = self.deviceMasterWidget
else:
self.currentWidget = self.deviceSlavrWidget
# 重新添加Widget保持居中
self.contentLayout.insertWidget(1, self.currentWidget) # 插入到两个弹簧中间
self.currentWidget.show()