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彩色化Linux的命令行终端界面的代码实例分享
Jul 02 Python
Python字典操作详细介绍及字典内建方法分享
Jan 04 Python
Python中循环后使用list.append()数据被覆盖问题的解决
Jul 01 Python
python MNIST手写识别数据调用API的方法
Aug 08 Python
Pycharm+Python+PyQt5使用详解
Sep 25 Python
numpy创建单位矩阵和对角矩阵的实例
Nov 29 Python
Django与pyecharts结合的实例代码
May 13 Python
django使用graphql的实例
Sep 02 Python
Pycharm中使用git进行合作开发的教程详解
Nov 17 Python
opencv实现图像几何变换
Mar 24 Python
Python中threading库实现线程锁与释放锁
May 17 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
php中ob(Output Buffer 输出缓冲)函数使用方法
2007/07/21 PHP
PHP变量的定义、可变变量、变量引用、销毁方法
2013/12/20 PHP
thinkPHP中volist标签用法示例
2016/12/06 PHP
启用OPCache提高PHP程序性能的方法
2019/03/21 PHP
javascript中[]和{}对象使用介绍
2013/03/20 Javascript
jQuery滚动条插件nanoscroller使用指南
2015/04/21 Javascript
简介可以自动完成UI的AngularJS工具angular-smarty
2015/06/23 Javascript
jQuery匹配文档链接并添加class的方法
2015/06/26 Javascript
JQuery实现级联下拉框效果实例讲解
2015/09/17 Javascript
nodejs+express搭建多人聊天室步骤
2018/02/12 NodeJs
JQuery获得内容和属性方法解析
2020/05/30 jQuery
微信小程序实现打卡签到页面
2020/09/21 Javascript
解决vue中使用less/sass及使用中遇到无效的问题
2020/10/24 Javascript
Vue指令实现OutClick的示例
2020/11/16 Javascript
Javascript新手入门之字符串拼接与变量的应用
2020/12/03 Javascript
全面解析Vue中的$nextTick
2020/12/24 Vue.js
[01:49]一目了然!DOTA2DotA快捷操作对比第二弹
2014/05/16 DOTA
[36:37]2014 DOTA2华西杯精英邀请赛5 24 VG VS iG
2014/05/25 DOTA
Python多线程学习资料
2012/12/19 Python
对python字典过滤条件的实例详解
2019/01/22 Python
python生成带有表格的图片实例
2019/02/03 Python
python编写简单端口扫描器
2019/09/04 Python
python sklearn常用分类算法模型的调用
2019/10/16 Python
Python实现树莓派摄像头持续录像并传送到主机的步骤
2020/11/30 Python
CSS3实现类似翻书效果的过渡动画的示例代码
2019/09/06 HTML / CSS
html5定制表单_动力节点Java学院整理
2017/07/11 HTML / CSS
HTML5进阶段内联标签汇总(小篇)
2016/07/13 HTML / CSS
前端实现打印图像功能
2019/08/27 HTML / CSS
某个公司的Java笔面试题
2016/03/11 面试题
大学生学习自我评价
2014/01/13 职场文书
文明学生标兵事迹
2014/01/21 职场文书
工程质量承诺书范文
2014/03/27 职场文书
公司委托书范本
2014/04/04 职场文书
科学发展观活动总结
2014/08/28 职场文书
2015年度工程师评职称工作总结
2015/10/14 职场文书
CSS使用伪类控制边框长度的方法
2022/01/18 HTML / CSS