Pyqt python 界面代码

1、界面拖动代码

python 复制代码
# 拖动
def mousePressEvent(self, event):
    if event.button() == QtCore.Qt.LeftButton and self.isMaximized() == False:
        self.m_flag = True
        self.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 = False
    self.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))

2、获取显示器分辨率

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

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

python 复制代码
# 变换最大化按钮图标
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 / 720
    else:
        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、侧边栏随动代码

python 复制代码
# 设置侧边伸缩菜单
def slideLeftMenu(self):
    width = self.ui.frame.width()
    if width == 46:
        newWidth = 130
        self.ui.pushButton.setIcon(QIcon(":/icons/icon/双左_double-left.png"))
    else:
        newWidth = 46
        self.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、设置保存,加载上次保存设置

python 复制代码
# 加载上次登录信息
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())
相关推荐
凯子坚持 c2 天前
当Python遇见高德:基于PyQt与JS API构建桌面三维地形图应用实战
javascript·python·pyqt·高德地图
Goona_2 天前
pyqt+Python证件号智能校验工具
pyqt
大学生毕业题目3 天前
毕业项目推荐:52-基于yolov8/yolov5/yolo11的红绿灯检测识别系统(Python+卷积神经网络)
人工智能·python·yolo·目标检测·cnn·pyqt·红绿灯检测
大学生毕业题目4 天前
毕业项目推荐:64-基于yolov8/yolov5/yolo11的蝴蝶种类检测识别系统(Python+卷积神经网络)
人工智能·python·yolo·目标检测·cnn·pyqt·蝴蝶检测
大学生毕业题目4 天前
毕业项目推荐:51-基于yolov8/yolov5/yolo11的反光衣检测识别系统(Python+卷积神经网络)
人工智能·python·yolo·目标检测·cnn·pyqt·反光衣检测
深兰科技5 天前
柳州市委常委、统战部部长,副市长潘展东率队首访深兰科技集团新总部,共探 AI 赋能制造大市与东盟合作新局
人工智能·beautifulsoup·numpy·pyqt·matplotlib·pygame·深兰科技
傻啦嘿哟8 天前
用PyQt快速搭建桌面应用:从零到实战的实用指南
pyqt
大学生毕业题目9 天前
毕业项目推荐:28-基于yolov8/yolov5/yolo11的电塔危险物品检测识别系统(Python+卷积神经网络)
人工智能·python·yolo·cnn·pyqt·电塔·危险物品
Ciel_752110 天前
AmazeVault 核心功能分析,认证、安全和关键的功能
python·pyqt·pip
不知名君13 天前
PyQt图表PyQtGraph多图光标同步pglive
pyqt