python实现分页效果


Posted in Python onOctober 25, 2017

本文实例为大家分享了python实现分页效果展示的具体代码,供大家参考,具体内容如下

难点:清空Layout

#!/usr/bin/python  
#-*-coding:utf-8-*- 
 
from PyQt4.QtCore import * 
from PyQt4.QtGui import * 
 
class PageWidget(QWidget): 
  def __init__(self,parent=None): 
    super(PageWidget,self).__init__(parent) 
    self.btns=[] 
    self.count=0 
    self.presign=0      #当前点击标识 
    self.nextsign=0     #当前点击标识 
    self.pre_button=QPushButton() 
    self.pre_button.setText("<<") 
    self.pre_button.setFixedSize(25,25) 
    self.connect(self.pre_button,SIGNAL("clicked()"),self,SLOT("prepage()")) 
    self.next_button=QPushButton() 
    self.next_button.setText(">>") 
    self.connect(self.next_button,SIGNAL("clicked()"),self,SLOT("nextpage()")) 
    self.next_button.setFixedSize(25,25) 
    self.center_layout=QHBoxLayout() 
    self.nextpage() 
 
    self.page_layput=QHBoxLayout() 
    self.page_layput.addWidget(self.pre_button) 
    self.page_layput.addLayout(self.center_layout) 
    self.page_layput.addWidget(self.next_button) 
    self.setLayout(self.page_layput) 
 
  @pyqtSlot() 
  def prepage(self): 
    self.presign=1 
    self.num=0 
    if (len(self.btns)>0) and (self.count>=10): 
      for p in range(10): 
        self.center_layout.removeWidget(self.btns[p]) 
        self.btns[p].deleteLater() 
      self.btns=[] 
    if self.count>=10: 
      if self.nextsign==1: 
        self.count=self.count-20 
        self.nextsign=0 
      else: 
        self.count=self.count-10 
      self.num=self.count 
 
      for i in range(10): 
        self.num+=1 
        self.center_button=QPushButton() 
        self.center_button.setText(str(self.num)) 
        self.center_button.setFixedSize(25,25) 
        self.btns.append(self.center_button) 
        self.center_layout.addWidget(self.center_button) 
      #print self.count 
  @pyqtSlot() 
  def nextpage(self): 
    self.nextsign=1 
    if len(self.btns)>0: 
      for p in range(10): 
        self.center_layout.removeWidget(self.btns[p]) 
        self.btns[p].deleteLater() 
      self.btns=[] 
    if self.presign==1: 
      self.count=self.count+10 
      self.presign=0 
    #mapper转有参数 
    signal_mapper = QSignalMapper(self) 
    for i in range(10): 
      self.count+=1 
      self.center_button=QPushButton() 
      self.center_button.setText(str(self.count)) 
      self.center_button.setFixedSize(25,25) 
      self.btns.append(self.center_button) 
      self.connect(self.center_button,SIGNAL("clicked()"),signal_mapper,SLOT("map()")) 
      signal_mapper.setMapping(self.center_button, str(self.count)) 
      self.center_layout.addWidget(self.center_button) 
    self.connect(signal_mapper, SIGNAL("mapped(QString)"), self, SLOT("showpage(QString)")) 
    #print self.count 
 
  @pyqtSlot(QString) 
  def showpage(self,page): 
    print page 
 
if __name__=='__main__': 
  import sys 
  app=QApplication(sys.argv) 
  page=PageWidget() 
  page.show() 
  sys.exit(app.exec_())

 效果图:

python实现分页效果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python抓取百度首页的方法
May 19 Python
Python错误提示:[Errno 24] Too many open files的分析与解决
Feb 16 Python
Python单元测试简单示例
Jul 03 Python
详解Python下Flask-ApScheduler快速指南
Nov 04 Python
Ubuntu下升级 python3.7.1流程备忘(推荐)
Dec 10 Python
Django使用redis缓存服务器的实现代码示例
Apr 28 Python
python 实现查找文件并输出满足某一条件的数据项方法
Jun 12 Python
python3 下载网络图片代码实例
Aug 27 Python
django框架中ajax的使用及避开CSRF 验证的方式详解
Dec 11 Python
kafka监控获取指定topic的消息总量示例
Dec 23 Python
Python错误的处理方法
Jun 23 Python
使用AJAX和Django获取数据的方法实例
Oct 25 Python
python+pyqt实现12306图片验证效果
Oct 25 #Python
python编程羊车门问题代码示例
Oct 25 #Python
python中requests使用代理proxies方法介绍
Oct 25 #Python
python中requests爬去网页内容出现乱码问题解决方法介绍
Oct 25 #Python
python编程之requests在网络请求中添加cookies参数方法详解
Oct 25 #Python
Python探索之pLSA实现代码
Oct 25 #Python
python正则表达式re之compile函数解析
Oct 25 #Python
You might like
Windows2003 下 MySQL 数据库每天自动备份
2006/12/21 PHP
php框架Phpbean说明
2008/01/10 PHP
PHP session_start()问题解疑(详细介绍)
2013/07/05 PHP
PHP中$_SERVER的详细参数与说明介绍
2013/10/26 PHP
php检测数组长度函数sizeof与count用法
2014/11/17 PHP
php简单计算年龄的方法(周岁与虚岁)
2016/12/06 PHP
PHP对称加密算法(DES/AES)类的实现代码
2017/11/14 PHP
浅析PHP反序列化中过滤函数使用不当导致的对象注入问题
2020/02/15 PHP
由JavaScript技术实现的web小游戏(不含网游)
2010/06/12 Javascript
jQuery后代选择器用法实例
2014/12/23 Javascript
使用javascript实现简单的选项卡切换
2015/01/09 Javascript
js实现九宫格图片半透明渐显特效的方法
2015/02/16 Javascript
jQuery获取字符串中出现最多的数
2016/02/22 Javascript
原生javascript+css3编写的3D魔方动画旋扭特效
2016/03/14 Javascript
Vue入门之animate过渡动画效果
2018/04/08 Javascript
vue.js实现照片放大功能
2020/06/23 Javascript
vue实现简单图片上传
2020/06/30 Javascript
9个JavaScript日常开发小技巧
2020/10/06 Javascript
Python 多线程抓取图片效率对比
2016/02/27 Python
Python高级用法总结
2018/05/26 Python
pycharm 将django中多个app放到同个文件夹apps的处理方法
2018/05/30 Python
便捷提取python导入包的属性方法
2018/10/15 Python
python温度转换华氏温度实现代码
2020/12/06 Python
使用豆瓣源来安装python中的第三方库方法
2021/01/26 Python
一加手机美国官方网站:OnePlus美国
2019/09/19 全球购物
Linux Interview Questions For software testers
2012/06/02 面试题
创建市级文明单位实施方案
2014/03/01 职场文书
幼儿教师培训感言
2014/03/08 职场文书
舞蹈专业大学生职业规划范文
2014/03/12 职场文书
请假条标准格式规范
2014/04/10 职场文书
教师考核评语
2014/04/28 职场文书
人力资源管理专业自荐信
2014/06/24 职场文书
健康状况证明书
2014/11/26 职场文书
五年级学生评语大全
2014/12/26 职场文书
教师节慰问信
2015/02/15 职场文书
银行柜员工作心得体会
2016/01/23 职场文书