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())
相关推荐
En^_^Joy19 小时前
PyQt常用控件的使用:QFileDialog、QMessageBox、QTreeWidget、QRadioButton等
开发语言·python·pyqt
zhlei_123451 天前
封闭内网安装配置VSCode Anconda3 并配置 PyQt5开发
ide·vscode·pyqt
猫头虎3 天前
零基础安装 Python 教程:从下载到环境配置一步到位(支持 VSCode 和 PyCharm)与常用操作系统操作指南
vscode·python·pycharm·beautifulsoup·numpy·pyqt·pip
江畔柳前堤10 天前
PyQt学习系列08-插件系统与模块化开发
运维·开发语言·数据库·python·学习·机器学习·pyqt
江畔柳前堤13 天前
PyQt学习系列05-图形渲染与OpenGL集成
开发语言·javascript·人工智能·python·学习·ecmascript·pyqt
江畔柳前堤14 天前
PyQt学习系列11-综合项目:多语言文件管理器
开发语言·网络·python·学习·django·pyqt
幽络源小助理14 天前
基于Yolov8+PyQT的老人摔倒识别系统源码
yolo·pyqt
江畔柳前堤14 天前
PyQt学习系列07-数据库操作与ORM集成
数据库·学习·算法·机器学习·架构·pyqt
江畔柳前堤15 天前
PyQt学习系列10-性能优化与调试技巧
开发语言·javascript·数据库·学习·性能优化·ecmascript·pyqt
钢铁男儿23 天前
PyQt 探索QMainWindow:打造专业的PyQt5主窗
python·qt·pyqt