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中bisect的用法
Sep 23 Python
详解Python中列表和元祖的使用方法
Apr 25 Python
python实现unicode转中文及转换默认编码的方法
Apr 29 Python
解读python logging模块的使用方法
Apr 17 Python
Python之读取TXT文件的方法小结
Apr 27 Python
Python 爬取携程所有机票的实例代码
Jun 11 Python
解决Python获取字典dict中不存在的值时出错问题
Oct 17 Python
python实现小球弹跳效果
May 10 Python
python监控进程状态,记录重启时间及进程号的实例
Jul 15 Python
Python3之字节串bytes与字节数组bytearray的使用详解
Aug 27 Python
Python更换pip源方法过程解析
May 19 Python
Python爬虫爬取百度搜索内容代码实例
Jun 05 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
DC最新动画电影:《战争之子》为何内容偏激,毁了一个不错的漫画
2020/04/09 欧美动漫
使用PHP制作新闻系统的思路
2006/10/09 PHP
模仿OSO的论坛(四)
2006/10/09 PHP
php超快高效率统计大文件行数
2015/07/05 PHP
PHP代码优化技巧小结
2015/09/29 PHP
fix-ie5.js扩展在IE5下不能使用的几个方法
2007/08/20 Javascript
JS的反射问题
2010/04/07 Javascript
html文本框提示效果的示例代码
2014/06/28 Javascript
javascript中实现兼容JAVA的hashCode算法代码分享
2020/08/11 Javascript
javascript简单实现图片预加载
2014/12/03 Javascript
深入理解JavaScript系列(41):设计模式之模板方法详解
2015/03/04 Javascript
node安装--linux下的快速安装教程
2017/03/21 Javascript
vue元素实现动画过渡效果
2017/07/01 Javascript
BootStrap Table复选框默认选中功能的实现代码(从数据库获取到对应的状态进行判断是否为选中状态)
2017/07/11 Javascript
JS实现闭包中的沙箱模式示例
2017/09/07 Javascript
Node之简单的前后端交互(实例讲解)
2017/11/14 Javascript
JS中‘hello’与new String(‘hello’)引出的问题详解
2018/08/14 Javascript
vue框架中props的typescript用法详解
2020/02/17 Javascript
如何封装Vue Element的table表格组件
2021/02/06 Vue.js
python人人网登录应用实例
2014/09/26 Python
Python对文件操作知识汇总
2016/05/15 Python
详谈python3中用for循环删除列表中元素的坑
2018/04/19 Python
Django REST 异常处理详解
2020/07/15 Python
详解Python中如何将数据存储为json格式的文件
2020/11/18 Python
html5-canvas中使用clip抠出一个区域的示例代码
2018/05/25 HTML / CSS
HTML5单页面手势滑屏切换原理分析
2017/07/10 HTML / CSS
教育孩子心得体会
2014/01/01 职场文书
政风行风建设责任书
2014/07/23 职场文书
协会周年庆活动方案
2014/08/26 职场文书
初中国旗下的演讲稿
2014/08/28 职场文书
2014校长四风问题对照检查材料思想汇报
2014/09/16 职场文书
学前班语言教学计划
2015/01/20 职场文书
go语言map与string的相互转换的实现
2021/04/07 Golang
Python基础之pandas数据合并
2021/04/27 Python
能用CSS实现的就不要麻烦JavaScript了
2021/10/05 HTML / CSS
MySQL慢查询中的commit慢和binlog中慢事务的区别
2022/06/16 MySQL