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.
208 lines
6.4 KiB
Python
208 lines
6.4 KiB
Python
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QLabel, QComboBox, QPushButton
|
|
from PyQt5.QtCore import Qt
|
|
from PyQt5.QtGui import QFont
|
|
|
|
|
|
class SwitchVarModelDialog(QDialog):
|
|
"""变量值类型选择对话框"""
|
|
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
self.setWindowTitle('选择变量值类型')
|
|
self.setFixedSize(380, 300) # 增加高度避免遮挡,并保持与用户最新修改一致
|
|
self.setModal(True)
|
|
self.selectedType = None
|
|
|
|
# 设置窗口样式
|
|
self.setWindowFlags(Qt.Dialog | Qt.WindowCloseButtonHint)
|
|
|
|
# 应用样式
|
|
self.setStyleSheet(self.getStyleSheet())
|
|
|
|
self.setupUI()
|
|
|
|
def setupUI(self):
|
|
"""设置界面"""
|
|
# 创建主布局
|
|
mainLayout = QVBoxLayout()
|
|
mainLayout.setSpacing(20)
|
|
mainLayout.setContentsMargins(30, 30, 30, 30)
|
|
|
|
# 标题标签
|
|
titleLabel = QLabel('选择变量值类型')
|
|
titleLabel.setObjectName('titleLabel') # 用于样式表
|
|
mainLayout.addWidget(titleLabel)
|
|
|
|
# 说明标签
|
|
infoLabel = QLabel('请选择您要将变量切换到的值类型:')
|
|
infoLabel.setObjectName('infoLabel') # 用于样式表
|
|
mainLayout.addWidget(infoLabel)
|
|
|
|
# 创建combobox
|
|
self.comboBox = QComboBox()
|
|
self.comboBox.setObjectName('valueTypeComboBox') # 用于样式表
|
|
self.comboBox.addItems(['本地值', '远程值', '模拟值'])
|
|
self.comboBox.setCurrentText('本地值') # 默认选择本地值
|
|
mainLayout.addWidget(self.comboBox)
|
|
|
|
# 添加更多弹性空间,确保按钮不会遮挡下拉框
|
|
mainLayout.addStretch(2)
|
|
|
|
# 创建按钮布局
|
|
buttonLayout = QHBoxLayout()
|
|
buttonLayout.setSpacing(15)
|
|
|
|
# 确定按钮
|
|
okButton = QPushButton('确定')
|
|
okButton.setObjectName('okButton') # 用于样式表
|
|
okButton.clicked.connect(self.accept)
|
|
buttonLayout.addWidget(okButton)
|
|
|
|
# 取消按钮
|
|
cancelButton = QPushButton('取消')
|
|
cancelButton.setObjectName('cancelButton') # 用于样式表
|
|
cancelButton.clicked.connect(self.reject)
|
|
buttonLayout.addWidget(cancelButton)
|
|
|
|
mainLayout.addLayout(buttonLayout)
|
|
self.setLayout(mainLayout)
|
|
|
|
def getSelectedType(self):
|
|
"""获取选择的类型"""
|
|
return self.comboBox.currentText()
|
|
|
|
def getStyleSheet(self):
|
|
"""返回对话框的样式表"""
|
|
return """
|
|
QDialog {
|
|
background-color: #F8F9FA;
|
|
border-radius: 12px;
|
|
border: 1px solid #E5E7EB;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
QLabel#titleLabel {
|
|
font-size: 18px;
|
|
font-weight: 600;
|
|
color: #1F2937;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
QLabel#infoLabel {
|
|
font-size: 14px;
|
|
color: #6B7280;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
QComboBox#valueTypeComboBox {
|
|
border: 1px solid #D1D5DB;
|
|
border-radius: 8px;
|
|
padding: 8px 12px;
|
|
font-size: 14px;
|
|
color: #374151;
|
|
background-color: #FFFFFF;
|
|
min-height: 36px;
|
|
}
|
|
|
|
QComboBox#valueTypeComboBox:hover {
|
|
border-color: #9CA3AF;
|
|
}
|
|
|
|
QComboBox#valueTypeComboBox:focus {
|
|
border-color: #2277EF;
|
|
outline: none;
|
|
}
|
|
|
|
QComboBox#valueTypeComboBox::drop-down {
|
|
subcontrol-origin: padding;
|
|
subcontrol-position: top right;
|
|
width: 25px;
|
|
border-left-width: 1px;
|
|
border-left-color: #D1D5DB;
|
|
border-left-style: solid;
|
|
border-top-right-radius: 8px;
|
|
border-bottom-right-radius: 8px;
|
|
}
|
|
|
|
QComboBox#valueTypeComboBox::down-arrow {
|
|
image: url(./Static/down_arrow.png); /* 假设有一个向下箭头图标 */
|
|
width: 16px;
|
|
height: 16px;
|
|
}
|
|
|
|
QComboBox#valueTypeComboBox QAbstractItemView {
|
|
border: 1px solid #E5E7EB;
|
|
border-radius: 8px;
|
|
background-color: #FFFFFF;
|
|
selection-background-color: #EBF8FF;
|
|
selection-color: #1D4ED8;
|
|
outline: none;
|
|
padding: 5px;
|
|
}
|
|
|
|
QComboBox#valueTypeComboBox QAbstractItemView::item {
|
|
min-height: 32px;
|
|
padding: 5px 10px;
|
|
border-radius: 6px;
|
|
}
|
|
|
|
QComboBox#valueTypeComboBox QAbstractItemView::item:hover {
|
|
background-color: #F3F4F6;
|
|
}
|
|
|
|
/* 使用项目之前的按钮样式 */
|
|
QPushButton {
|
|
border: none;
|
|
outline: none;
|
|
font-family: "PingFangSC-Medium", "Microsoft YaHei", sans-serif;
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
padding: 8px 16px;
|
|
border-radius: 6px;
|
|
min-width: 80px;
|
|
min-height: 32px;
|
|
}
|
|
|
|
/* 确定按钮样式 - 使用项目蓝色主题 */
|
|
QPushButton#okButton {
|
|
background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
|
|
stop:0 #2277EF,
|
|
stop:1 #1976D2);
|
|
color: #FFFFFF;
|
|
border: 1px solid #1976D2;
|
|
}
|
|
|
|
QPushButton#okButton:hover {
|
|
background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
|
|
stop:0 #3B82F6,
|
|
stop:1 #2277EF);
|
|
border-color: #2277EF;
|
|
}
|
|
|
|
QPushButton#okButton:pressed {
|
|
background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
|
|
stop:0 #1976D2,
|
|
stop:1 #1565C0);
|
|
border-color: #1565C0;
|
|
}
|
|
|
|
/* 取消按钮样式 - 使用项目灰色主题 */
|
|
QPushButton#cancelButton {
|
|
background-color: #F9FAFB;
|
|
color: #6B7280;
|
|
border: 1px solid #E5E7EB;
|
|
}
|
|
|
|
QPushButton#cancelButton:hover {
|
|
background-color: #F3F4F6;
|
|
border-color: #D1D5DB;
|
|
color: #4B5563;
|
|
}
|
|
|
|
QPushButton#cancelButton:pressed {
|
|
background-color: #E5E7EB;
|
|
border-color: #9CA3AF;
|
|
color: #374151;
|
|
}
|
|
"""
|