fromPyQt5.QtCoreimportQCoreApplicationfromPyQt5.QtGuiimportQIconfromPyQt5.QtWidgetsimportQWidget,QPushButton,QDesktopWidget,QMessageBoxclassAppQWidget(QWidget):""" A custom QWidget by Rust Fisher """def__init__(self):super().__init__()self.init_ui()definit_ui(self):# self.setGeometry(300, 300, 400, 200) # 相当于move和resizeself.resize(300,200)self.move_to_center()self.setWindowTitle('Demo1')self.setWindowIcon(QIcon('res/fish.jpg'))btn1=QPushButton('Quit',self)btn1.setToolTip('Click to quit')btn1.resize(btn1.sizeHint())btn1.move(200,150)btn1.clicked.connect(QCoreApplication.instance().quit)# cannot locate function connectdefcloseEvent(self,event):reply=QMessageBox.question(self,'Message','Are you sure to quit now?',QMessageBox.Yes|QMessageBox.No,QMessageBox.No)ifreply==QMessageBox.Yes:event.accept()else:event.ignore()defmove_to_center(self):qr=self.frameGeometry()cp=QDesktopWidget().availableGeometry().center()# got center info hereqr.moveCenter(cp)self.move(qr.topLeft())# 应用窗口的左上方的点到qr矩形的左上方的点,因此居中显示在我们的屏幕上
# 同组的控件可以存在同一个list中self.cb_list=[self.ma.i2cCB,self.ma.mipiCB,self.ma.eepromCB,self.ma.tem_sensorCB,self.ma.lensCB,self.ma.vcmCB,self.ma.mirrorCB,self.ma.mirrorCaliCB,]self.test_count_et_list=[self.ma.i2cCountEt,self.ma.mipiCountEt,self.ma.eepromCountEt,self.ma.tem_sensorCountEt,self.ma.lensCountEt,self.ma.vcmCountEt,self.ma.mirrorCountEt,self.ma.mirrorCaliCountEt,]# 需要操作某组控件时 直接遍历列表def_click_test_item_cb(self):""" Update [choose all checkbox] by all test item state """choose_all=Trueforcbinself.cb_list:choose_all=choose_all&cb.isChecked()self.ma.selecteAllCB.setChecked(choose_all)
classRustMainWindow(QMainWindow):""" This is the main class """def_trigger_english(self):print"Change to English",QApplication.instance()# Change to English <PyQt4.QtGui.QApplication object at 0x02ABE3A0>