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())
相关推荐
酷飞飞3 天前
PyQt 界面布局与交互组件使用指南
python·qt·交互·pyqt
qq_340474024 天前
Q3.1 PyQt 中的控件罗列
pyqt
万粉变现经纪人4 天前
如何解决pip安装报错ModuleNotFoundError: No module named ‘sympy’问题
python·beautifulsoup·pandas·scikit-learn·pyqt·pip·scipy
Goona_5 天前
PyQt数字转大写金额GUI工具开发及财务规范实现
python·小程序·交互·pyqt
小叮当⇔5 天前
PYcharm——pyqt音乐播放器
ide·pycharm·pyqt
青铜发条5 天前
【Qt】PyQt、原生QT、PySide6三者的多方面比较
开发语言·qt·pyqt
Goona_7 天前
pyqt+python之二进制生肖占卜
pyqt
大学生毕业题目9 天前
毕业项目推荐:83-基于yolov8/yolov5/yolo11的农作物杂草检测识别系统(Python+卷积神经网络)
人工智能·python·yolo·目标检测·cnn·pyqt·杂草识别
凯子坚持 c12 天前
当Python遇见高德:基于PyQt与JS API构建桌面三维地形图应用实战
javascript·python·pyqt·高德地图