163 lines
5.6 KiB
Python
163 lines
5.6 KiB
Python
|
import sys
|
|||
|
import time
|
|||
|
|
|||
|
from PyQt5.QtWidgets import *
|
|||
|
from PyQt5.QtCore import *
|
|||
|
|
|||
|
|
|||
|
class MyWindow(QWidget):
|
|||
|
|
|||
|
def __init__(self):
|
|||
|
super().__init__()
|
|||
|
self.setWindowTitle("信号与槽")
|
|||
|
self.init_ui()
|
|||
|
|
|||
|
# 主初始化方法
|
|||
|
def main_window_init(self):
|
|||
|
# 设置窗口大小
|
|||
|
self.resize(300, 200)
|
|||
|
# 主界面布局 [垂直布局]
|
|||
|
self.main_layout = QVBoxLayout()
|
|||
|
|
|||
|
def init_ui(self):
|
|||
|
self.main_window_init()
|
|||
|
|
|||
|
# 信息Box初始化
|
|||
|
self.message_widget_init()
|
|||
|
# 设置Box初始化
|
|||
|
self.seeting_widget_init()
|
|||
|
|
|||
|
# 将两个Group添加至主布局器中
|
|||
|
self.main_layout.addWidget(self.message_group_box)
|
|||
|
self.main_layout.addWidget(self.seeting_group_box)
|
|||
|
self.setLayout(self.main_layout)
|
|||
|
|
|||
|
# 信息部分初始化方法
|
|||
|
def message_widget_init(self):
|
|||
|
# 信息界面组Group
|
|||
|
self.message_group_box = QGroupBox("信息")
|
|||
|
|
|||
|
# 两个控件水平布局
|
|||
|
horizon_layout = QHBoxLayout()
|
|||
|
|
|||
|
# 控件1:设置转盘控件
|
|||
|
self.control_1 = QDial()
|
|||
|
# 是否循环滚动 [默认是]
|
|||
|
self.control_1.setWrapping(True)
|
|||
|
# 是否显示刻度
|
|||
|
self.control_1.setNotchesVisible(True)
|
|||
|
# 绑定信号至槽函数Dialg_Signal
|
|||
|
self.control_1.valueChanged.connect(self.Dialg_Signal)
|
|||
|
|
|||
|
# 控件2:信息框
|
|||
|
# 信息框垂直布局
|
|||
|
message_vertical_layout = QVBoxLayout()
|
|||
|
# 文字
|
|||
|
Message_Lable = QLabel("数值")
|
|||
|
# 信息框
|
|||
|
self.control_2 = QSpinBox()
|
|||
|
# 两个控件添加至垂直布局中
|
|||
|
message_vertical_layout.addWidget(self.control_2)
|
|||
|
message_vertical_layout.addWidget(Message_Lable)
|
|||
|
|
|||
|
# 两个控件绑定至垂直布局中
|
|||
|
horizon_layout.addWidget(self.control_1)
|
|||
|
horizon_layout.addLayout(message_vertical_layout)
|
|||
|
|
|||
|
# 将垂直布局添加至组中
|
|||
|
self.message_group_box.setLayout(horizon_layout)
|
|||
|
|
|||
|
# 设置部分初始化方法
|
|||
|
def seeting_widget_init(self):
|
|||
|
# 设置界面组Group
|
|||
|
self.seeting_group_box = QGroupBox("设置")
|
|||
|
# 控件网格布局
|
|||
|
self.grid_layout = QGridLayout()
|
|||
|
|
|||
|
# 设置项:是否显示刻度
|
|||
|
self.seeting_norchesvisible()
|
|||
|
self.seeting_notchesVisile()
|
|||
|
|
|||
|
# 显示刻度组添加至网格布局中
|
|||
|
self.grid_layout.addWidget(self.norchesvisible_group_box,1,1)
|
|||
|
# 是否循环组添加至网格布局中
|
|||
|
self.grid_layout.addWidget(self.notchesVisile_group_box,1,2)
|
|||
|
|
|||
|
# 将网格布局添加至主Group中
|
|||
|
self.seeting_group_box.setLayout(self.grid_layout)
|
|||
|
|
|||
|
# 设置项:是否显示刻度
|
|||
|
def seeting_norchesvisible(self):
|
|||
|
# 显示刻度组Group
|
|||
|
self.norchesvisible_group_box = QGroupBox("显示刻度")
|
|||
|
|
|||
|
# 下拉选框控件[是否显示刻度]
|
|||
|
self.Combo_NotchesVisible = QComboBox()
|
|||
|
# 该Group中为垂直布局
|
|||
|
norchesvisible_vertical_layout = QVBoxLayout()
|
|||
|
# 配置下拉选框是否可以编辑
|
|||
|
self.Combo_NotchesVisible.setEditable(False)
|
|||
|
|
|||
|
# 添加控件元素
|
|||
|
self.Combo_NotchesVisible.addItem("显示")
|
|||
|
self.Combo_NotchesVisible.addItem("不显示")
|
|||
|
|
|||
|
# 连接槽函数至seeting_norchesvisible_Signal
|
|||
|
self.Combo_NotchesVisible.currentIndexChanged.connect(self.seeting_norchesvisible_Signal)
|
|||
|
|
|||
|
# 将Combo_NotchesVisible[下拉选择框]添加至垂直布局中
|
|||
|
norchesvisible_vertical_layout.addWidget(self.Combo_NotchesVisible)
|
|||
|
# 将norchesvisible_vertical_layout[Group]添加至主Group中
|
|||
|
self.norchesvisible_group_box.setLayout(norchesvisible_vertical_layout)
|
|||
|
|
|||
|
# 设置项:是否允许转盘循环
|
|||
|
def seeting_notchesVisile(self):
|
|||
|
# 是否循环Group
|
|||
|
self.notchesVisile_group_box = QGroupBox("循环滚动")
|
|||
|
|
|||
|
# 下拉框选择控件
|
|||
|
self.Combo_notchesVisile = QComboBox()
|
|||
|
# 该Group内为垂直布局
|
|||
|
notchesVisile_vertical_layout = QVBoxLayout()
|
|||
|
# 配置下拉选框是否可以编辑
|
|||
|
self.Combo_NotchesVisible.setEditable(False)
|
|||
|
|
|||
|
# 添加控件元素
|
|||
|
self.Combo_notchesVisile.addItem("循环")
|
|||
|
self.Combo_notchesVisile.addItem("不循环")
|
|||
|
|
|||
|
# 连接槽函数至
|
|||
|
self.Combo_notchesVisile.currentIndexChanged.connect(self.seeting_notchesVisile_Signal)
|
|||
|
|
|||
|
# 将Combo_notchesVisile[下拉选择框]添加至垂直布局中
|
|||
|
notchesVisile_vertical_layout.addWidget(self.Combo_notchesVisile)
|
|||
|
# 将notchesVisile_vertical_layout[Group]添加至主Group中
|
|||
|
self.notchesVisile_group_box.setLayout(notchesVisile_vertical_layout)
|
|||
|
|
|||
|
# 转盘信号槽方法 [回调函数]
|
|||
|
def Dialg_Signal(self):
|
|||
|
self.control_2.setValue(self.control_1.value())
|
|||
|
|
|||
|
# 设置项:是否显示刻度 [回调函数]
|
|||
|
def seeting_norchesvisible_Signal(self):
|
|||
|
# 判断索引号:0[显示] 1[不显示]
|
|||
|
if self.Combo_NotchesVisible.currentIndex() == 0:
|
|||
|
self.control_1.setNotchesVisible(True)
|
|||
|
elif self.Combo_NotchesVisible.currentIndex() == 1:
|
|||
|
self.control_1.setNotchesVisible(False)
|
|||
|
|
|||
|
# 设置项:是否允许转盘循环 [回调函数]
|
|||
|
def seeting_notchesVisile_Signal(self):
|
|||
|
# 判断索引号:0[循环] 1[不循环]
|
|||
|
if self.Combo_notchesVisile.currentIndex() == 0:
|
|||
|
self.control_1.setWrapping(True)
|
|||
|
elif self.Combo_notchesVisile.currentIndex() == 1:
|
|||
|
self.control_1.setWrapping(False)
|
|||
|
if __name__ == '__main__':
|
|||
|
app = QApplication(sys.argv)
|
|||
|
|
|||
|
w = MyWindow()
|
|||
|
w.show()
|
|||
|
|
|||
|
app.exec()
|