码迷,mamicode.com
首页 > 其他好文 > 详细

pyqt5第二部分

时间:2021-04-14 12:17:20      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:mode   eva   mask   hang   label   date()   测试   tool   eric   

#定义界面类,继承父类QMainWindow,QtWidgets,Dialog
      class MainWindow(QMainWindow):
      #初始化函数,函数执行时候自动执行__init__()函数
          def __init__(self):
              super(MainWindow, self).__init__()
              self.initUI()
              #自定义各种信号应用
              self.signal = MultiSignal()
              #自定义信号和槽的链接测试
              mysignalslotapp()
      
      #界面函数定义,designer设计界面导入以及控件触发事件的设置(如:点击,状态、时间改变等)
          def initUI(self):
              self.ui = menuui.Ui_MainWindow()
              # 初始化界面
              self.ui.setupUi(self)
              #设置窗口透明度
              # self.setWindowOpacity(1)
              #抓取屏幕尺寸
              screen = QDesktopWidget().screenGeometry()
              #抓取软件见面尺寸
              size = self.geometry()
              #设置软件居中
              newtop = (screen.height()-size.height()) / 2
              newleft = (screen.width()-size.width()) / 2
              self.move(newleft , newtop)
      
      #--------------------------------------------------------------------------------------
      
              #菜单和工具栏操作函数定义
              self.ui.menufile.triggered.connect(self.processTrigger)
              self.ui.menuedit.triggered.connect(self.processTrigger)
              #设置工具栏图片和文字的位置
              self.ui.toolBar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
      # ************************************************************************************
      
      #-------------------------------------------------------------------------------------
              #状态栏目定义
              self.ui.statusBar = QStatusBar()
              self.setStatusBar(self.ui.statusBar)
      # **************************************************************************************
      
      #--------------------------------------------------------------------------------------
              #日历操作
              date = self.ui.calendarWidget.selectedDate()
              self.ui.labelcal.setText(date.toString("yyyy-MM-dd dddd"))
              self.ui.calendarWidget.clicked.connect(self.showDate)
      # *********************************************************************
      
      # --------------------------------------------------------------------------------------
              #时间日期操作
              self.ui.timeEdit.timeChanged.connect(self.onTimeChanged)
              self.ui.dateEdit.dateChanged.connect(self.onDateChanged)
              self.ui.dateTimeEdit.dateTimeChanged.connect(self.onDateTimeChanged)
              self.ui.timeEdit.setTime(QTime.currentTime())
              self.ui.labeltime.setText((QTime.currentTime().toString("HH:mm:ss")))
              self.ui.labelday.setText((QDate.currentDate().toString("yyyy-MM-dd dddd")))
              self.ui.labeldaytime.setText((QDateTime.currentDateTime().toString("yyyy/MM/dd dddd hh:mm:ss")))
      #************************************************************************************
      
      #------------------------------------------------------------------------------------
          #复选框操作
              self.ui.checkBox1.stateChanged.connect(lambda :self.checkboxState(self.ui.checkBox1))
              self.ui.checkBox2.stateChanged.connect(lambda :self.checkboxState(self.ui.checkBox2))
              self.ui.checkBox3.stateChanged.connect(lambda :self.checkboxState(self.ui.checkBox3))
      #*************************************************************************************
      
      #------------------------------------------------------------------------------------
          #下拉选择菜单QComboBox操作
              self.ui.comboBox.currentIndexChanged.connect(self.selectionChange)
              self.ui.comboBox.addItems(["php" ,"vb" , "sql"])
      #************************************************************************************
      
      #------------------------------------------------------------------------------------
             #label标签链接操作,注意链接操作和linkactiveted和标签链接只能选一个,Desiner里面
              #设置勾选openextennallink就是标签链接网页打开,linkclicked链接函数不执行,另外还要选择textselectbymouse
              self.ui.labelA.linkHovered.connect(self.linkHovered)
              self.ui.labella.linkActivated.connect(self.linkClicked)
      
      #***********************************************************************************#
      #Qedit输入限制
              self.ui.lineEditint.setValidator(QIntValidator())
              self.ui.lineEditdoub.setValidator(QDoubleValidator())
              self.ui.lineEditpassd.setEchoMode(QLineEdit.Password)
              self.ui.lineEditacc.textChanged.connect(self.textChanged)
              self.ui.lineEditpassd.editingFinished.connect(self.enterPress)
              self.ui.lineEditmask.setInputMask(‘000.000.000.000;_‘)
      #校验器输入
              #整形教验
              intValidator = QIntValidator(self)
              intValidator.setRange(0, 99)
              self.ui.lineEditintvor.setValidator(intValidator)
              #浮点型校验
              doubleValidator = QDoubleValidator(self)
              doubleValidator.setRange(-100 , 100)
              doubleValidator.setNotation(QDoubleValidator.StandardNotation)
              doubleValidator.setDecimals(3)
              self.ui.lineEditdvor.setValidator(doubleValidator)
              #字母数字校验
              # 字符和数字
              reg = QRegExp(‘[a-zA-z0-9]+$‘)
              validator = QRegExpValidator(self)
              validator.setRegExp(reg)
              self.ui.lineEditns.setValidator(validator)

pyqt5第二部分

标签:mode   eva   mask   hang   label   date()   测试   tool   eric   

原文地址:https://www.cnblogs.com/shalaotou/p/14655601.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!