当前位置: 首页 > wzjs >正文

宁波网站建设企业网站制作汝阳网站建设哪家好

宁波网站建设企业网站制作,汝阳网站建设哪家好,手机编辑网页,网站后台用什么开发通过python代码,基于PyQt5实现本地图片预览查看工具。 我们对窗口进行了圆角设计,图片的翻页按钮半透明处理,当鼠标移动至按钮上的动画效果,当选择某一张图片,进行左右翻页则轮播同目录所有支持的图片格式。 import …

通过python代码,基于PyQt5实现本地图片预览查看工具。

我们对窗口进行了圆角设计,图片的翻页按钮半透明处理,当鼠标移动至按钮上的动画效果,当选择某一张图片,进行左右翻页则轮播同目录所有支持的图片格式。

import sys
import os
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QLabel,QPushButton, QFileDialog, QHBoxLayout, QVBoxLayout,QMessageBox)
from PyQt5.QtGui import QPixmap, QIcon, QFont, QColor, QPainter
from PyQt5.QtCore import Qt, QSize, QPoint, QPropertyAnimation, QEasingCurveclass ImageViewer(QMainWindow):def __init__(self):super().__init__()self.current_file = Noneself.files = []self.current_index = -1self.original_pixmap = None  # 存储原始图片数据self.initUI()def initUI(self):# 窗口设置self.setWindowTitle('一个黑客创业者')self.setGeometry(100, 100, 1280, 800)self.setMinimumSize(800, 600)# 深色主题样式self.setStyleSheet("""QMainWindow {background-color: #1A1A1A;}QLabel#imageLabel {background-color: #000000;border: none;}#openButton {background-color: #4A90E2;color: white;padding: 12px 24px;border-radius: 8px;font-family: 'Segoe UI';font-size: 14px;min-width: 120px;}#openButton:hover {background-color: #357ABD;}#openButton:pressed {background-color: #2A5F8F;}#navButton {background-color: rgba(0, 0, 0, 0.5);color: rgba(255, 255, 255, 0.9);border-radius: 30px;font-size: 24px;}#navButton:hover {background-color: rgba(0, 0, 0, 0.7);}#navButton:disabled {color: rgba(255, 255, 255, 0.3);}""")# 主窗口部件central_widget = QWidget()self.setCentralWidget(central_widget)main_layout = QVBoxLayout(central_widget)main_layout.setContentsMargins(0, 0, 0, 0)main_layout.setSpacing(0)# 图片显示区域self.image_label = QLabel()self.image_label.setObjectName("imageLabel")self.image_label.setAlignment(Qt.AlignCenter)main_layout.addWidget(self.image_label)# 底部控制栏self.create_bottom_bar()# 悬浮导航按钮self.create_floating_controls()# 初始化按钮状态self.update_nav_buttons()def create_bottom_bar(self):# 底部控制栏bottom_bar = QWidget()bottom_bar.setFixedHeight(80)bottom_bar.setStyleSheet("background-color: rgba(26, 26, 26, 0.9);")layout = QHBoxLayout(bottom_bar)layout.setContentsMargins(40, 0, 40, 0)self.btn_open = QPushButton(" 打开图片", self)self.btn_open.setObjectName("openButton")self.btn_open.setIcon(QIcon.fromTheme("document-open"))self.btn_open.setIconSize(QSize(20, 20))layout.addStretch()layout.addWidget(self.btn_open)layout.addStretch()self.centralWidget().layout().addWidget(bottom_bar)# 信号连接self.btn_open.clicked.connect(self.open_image)def create_floating_controls(self):# 左侧导航按钮self.btn_prev = QPushButton("◀", self)self.btn_prev.setObjectName("navButton")self.btn_prev.setFixedSize(60, 60)# 右侧导航按钮self.btn_next = QPushButton("▶", self)self.btn_next.setObjectName("navButton")self.btn_next.setFixedSize(60, 60)# 为每个按钮创建独立的动画对象self.prev_animation = QPropertyAnimation(self.btn_prev, b"pos")self.prev_animation.setEasingCurve(QEasingCurve.OutQuad)self.next_animation = QPropertyAnimation(self.btn_next, b"pos")self.next_animation.setEasingCurve(QEasingCurve.OutQuad)# 信号连接self.btn_prev.clicked.connect(self.prev_image)self.btn_next.clicked.connect(self.next_image)def resizeEvent(self, event):# 更新按钮位置nav_y = self.height() // 2 - 30self.btn_prev.move(30, nav_y)self.btn_next.move(self.width() - 90, nav_y)# 更新图片显示(使用缓存的原始图片)self.update_pixmap()super().resizeEvent(event)def open_image(self):try:file_path, _ = QFileDialog.getOpenFileName(self, "选择图片", "","图片文件 (*.png *.jpg *.jpeg *.bmp *.gif)")if file_path:self.load_image(file_path)self.update_file_list(file_path)except Exception as e:self.show_error("打开失败", str(e))def load_image(self, file_path):try:pixmap = QPixmap(file_path)if pixmap.isNull():raise ValueError("不支持的图片格式")self.original_pixmap = pixmap  # 保存原始图片self.update_pixmap()self.current_file = file_pathexcept Exception as e:self.show_error("加载失败", str(e))self.image_label.clear()def update_pixmap(self):"""根据当前窗口尺寸更新显示图片"""if self.original_pixmap:scaled = self.original_pixmap.scaled(self.image_label.size() - QSize(2, 2),Qt.KeepAspectRatio,Qt.SmoothTransformation)self.image_label.setPixmap(scaled)def update_file_list(self, file_path):try:directory = os.path.dirname(file_path)self.files = sorted([os.path.normpath(os.path.join(directory, f))for f in os.listdir(directory)if f.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif'))])normed_file_path = os.path.normpath(file_path)if normed_file_path not in self.files:raise FileNotFoundError(f"{normed_file_path} 不在这个目录中")self.current_index = self.files.index(normed_file_path)self.update_nav_buttons()except Exception as e:self.show_error("列表更新失败", str(e))def prev_image(self):if self.current_index > 0:self.current_index -= 1self.load_image(self.files[self.current_index])self.update_nav_buttons()self.animate_nav_button(self.btn_prev)def next_image(self):if self.current_index < len(self.files) - 1:self.current_index += 1self.load_image(self.files[self.current_index])self.update_nav_buttons()self.animate_nav_button(self.btn_next)def update_nav_buttons(self):self.btn_prev.setEnabled(self.current_index > 0)self.btn_next.setEnabled(self.current_index < len(self.files) - 1)def animate_nav_button(self, button):"""改进后的按钮动画方法"""animation = self.prev_animation if button == self.btn_prev else self.next_animationoriginal_pos = button.pos()offset = QPoint(-10, 0) if button == self.btn_prev else QPoint(10, 0)animation.stop()animation.setStartValue(original_pos + offset)animation.setEndValue(original_pos)animation.setDuration(200)animation.start()def show_error(self, title, message):QMessageBox.critical(self, title,f"<span style='color:#fff;font-size:14px;'>{message}</span>",QMessageBox.Ok)if __name__ == '__main__':app = QApplication(sys.argv)# 设置全局字体font = QFont("Microsoft YaHei" if sys.platform == 'win32' else "Arial")app.setFont(font)viewer = ImageViewer()viewer.show()sys.exit(app.exec_())


文章转载自:

http://YWSSkU6d.pcrzf.cn
http://FFitoEjb.pcrzf.cn
http://UFbUVT3S.pcrzf.cn
http://70m7YKiT.pcrzf.cn
http://yHnXqr6v.pcrzf.cn
http://U19qgzmK.pcrzf.cn
http://sbK4hPlQ.pcrzf.cn
http://bPSSAQL9.pcrzf.cn
http://H1Rdae3E.pcrzf.cn
http://sTDX7zab.pcrzf.cn
http://r0CBR5w7.pcrzf.cn
http://L100Xv7R.pcrzf.cn
http://nS9NbQrx.pcrzf.cn
http://QY2iMOF5.pcrzf.cn
http://j0nMgrk4.pcrzf.cn
http://2f8p7GAZ.pcrzf.cn
http://NfJ5fuMi.pcrzf.cn
http://PTjLiMid.pcrzf.cn
http://6UDNDkvI.pcrzf.cn
http://1oaVq5bA.pcrzf.cn
http://sfMkv8mp.pcrzf.cn
http://tmlsd3NB.pcrzf.cn
http://P7RMp4m2.pcrzf.cn
http://3FiHHcby.pcrzf.cn
http://CU2YRkTz.pcrzf.cn
http://X1dZ5Raw.pcrzf.cn
http://lsNsaRHT.pcrzf.cn
http://LHV1vuIu.pcrzf.cn
http://k2GXuRKF.pcrzf.cn
http://tkTFhSB0.pcrzf.cn
http://www.dtcms.com/wzjs/634148.html

相关文章:

  • 网站怎么做更新吗全屋定制十大名牌品牌
  • 网站维护的内容和步骤平面设计在家接单收入
  • 找能做网站的深圳网站设计go
  • 保定做网站建设做网站 使用权 所有权
  • 镇江手机网站建设公司网站过期未续费会怎样
  • gate网站合约怎么做空网站建设丨选择金手指排名15
  • 毕设网站建设论文用windows建设网站好吗
  • 网站内容 优化全国十大展陈设计公司
  • 做天猫网站价格表网站建设收费标准如何
  • 微网站开发 培训北京冬奥会火炬设计制作
  • 网站建设代理多少钱学院网站建设招标书
  • 品牌网站建设公司排名网络营销外包是干啥的
  • 有网站和无网站的区别网站个人备案做企业网站
  • wordpress关闭网站wordpress菜单教程
  • 网站的建设ppt服务平台入口
  • 岗网站制作对外贸营销型网站建设的几点建议
  • 与电子商务网站建设有关实训报告自己设计室内装修软件
  • 分类信息网站程序wordpress付费发布
  • 外贸cms建站做化妆品代理在那些网站比较多
  • 设计素材网站有哪些平台门户网站建设进一步提升
  • wordpress 图片2m做网站和seo哪个好
  • 官网的建站过程小程序开发语言
  • 微信网站怎么做系统开发生命周期
  • 手机网站设计咨询discuz x3.2整合wordpress
  • 中国建设银行英文网站做二手车有哪些网站有哪些手续
  • 网站权重排行榜网站制作方案要点
  • 求一个好用的网站wordpress网站建设教程视频
  • 推广网站怎样做网站建设 自动生成
  • 爱站网站排行榜教做美食的网站
  • 安徽网站建设推荐公司网站站群是什么