1、界面拖动代码

# 拖动def mousePressEvent(self, event):if event.button() == QtCore.Qt.LeftButton and self.isMaximized() == False:self.m_flag = Trueself.m_Position = event.globalPos() - self.pos()# 获取鼠标相对窗口的位置event.accept()self.setCursor(QtGui.QCursor(QtCore.Qt.OpenHandCursor))# 更改鼠标图标def mouseMoveEvent(self, mouse_event):if QtCore.Qt.LeftButton and self.m_flag:self.move(mouse_event.globalPos() - self.m_Position)# 更改窗口位置mouse_event.accept()def mouseReleaseEvent(self, mouse_event):self.m_flag = Falseself.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))

2、获取显示器分辨率

#获取显示器分辨率self.desktop = QApplication.desktop()self.screenRect = self.desktop.screenGeometry()self.screenheight = self.screenRect.height()self.screenwidth = self.screenRect.width()

3、pyqt界面随界面大小变化图标

# 变换最大化按钮图标def resize_win(self):if self.isFullScreen():self.showNormal()self.ui.pushButton_maxsize.setIcon(QtGui.QIcon(u":/icon/icon/全屏黑.png"))Width_value = self.ui.label_show_camera.height()self.Width_fy = Width_value / 720else:self.showFullScreen()self.ui.pushButton_maxsize.setIcon(QtGui.QIcon(u":/icon/icon/最小化黑.png"))Width_value = self.ui.label_show_camera.height()self.Width_fy = Width_value / 720

4、侧边栏随动代码

# 设置侧边伸缩菜单def slideLeftMenu(self):width = self.ui.frame.width()if width == 46:newWidth = 130self.ui.pushButton.setIcon(QIcon(":/icons/icon/双左_double-left.png"))else:newWidth = 46self.ui.pushButton.setIcon(QIcon(":/icons/icon/双右_double-right.png"))animation = QPropertyAnimation(self.ui.frame, b"minimumWidth", self)animation.setStartValue(width)animation.setEndValue(newWidth)animation.setDuration(200)animation.start()

5、设置保存,加载上次保存设置

# 加载上次登录信息def read_config_info(self):settings = QSettings("config.ini", QSettings.IniFormat)# 方法1:使用配置文件# self.ui.lineEdit_list_fxdpath.setText(settings.value("page_list/filename_fxd"))# 包装程序时记得注释此行self.ui.lineEdit_list_xhdpath.setText(settings.value("page_list/filename_xhd"))self.ui.lineEdit_list_bgpath.setText(settings.value("page_list/foldername_bg"))self.ui.lineEdit_list_qzr.setText(settings.value("page_list/qzrname"))# 保存上次登录设置信息def save_config_info(self):settings = QSettings("config.ini", QSettings.IniFormat)# 方法1:使用配置文件# settings = QSettings("mysoft","myapp")#方法2:使用注册表# settings.setValue("page_list/filename_fxd", self.ui.lineEdit_list_fxdpath.text())# 包装程序时记得注释此行settings.setValue("page_list/filename_xhd", self.ui.lineEdit_list_xhdpath.text())settings.setValue("page_list/foldername_bg", self.ui.lineEdit_list_bgpath.text())settings.setValue("page_list/qzrname", self.ui.lineEdit_list_qzr.text())