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())