• pyqt 发射接收信号


    翻页控件:

    一、定义并发射信号:

      1 #!/usr/bin/python
      2 # #coding=utf-8
      3 # __author__=''
      4 
      5 
      6 from PyQt4.QtCore import *
      7 from PyQt4.QtGui import *
      8 
      9 import pageItem_ui
     10 
     11 
     12 class pageItem(QWidget):
     13     # 定义信号
     14     emit_page_changed = pyqtSignal(int, int)
     15 
     16     def __init__(self, parent=None):
     17         QWidget.__init__(self, parent)
     18         self.ui = pageItem_ui.Ui_Form()
     19 
     20         self.page_num = 1
     21         self.page_rows = 50
     22         self.total_page = 0
     23         self.init_ui()
     24         self.init_ui_data()
     25 
     26     def init_ui(self):
     27         self.setObjectName('pageItem')
     28         self.ui.setupUi(self)
     29         self.setStyleSheet("QComboBox QAbstractItemView::item{height:25px;}")
     30         self.ui.comboBox_show_page_num.setView(QListView())
     31 
     32         regExp = QRegExp('^[1-9][0-9]*$')
     33         self.ui.comboBox_show_page_num.setValidator(QIntValidator(1, 999, self))
     34         self.ui.lineEdit_jump_page.setValidator(QRegExpValidator(regExp, self))
     35 
     36         self.connect(self.ui.pushButton_jump, SIGNAL('clicked()'), self.slot_pushButton_jump_clicked)
     37         self.connect(self.ui.pushButton_per_page, SIGNAL('clicked()'), self.slot_pushButton_per_clicked)
     38         self.connect(self.ui.pushButton_next_page, SIGNAL('clicked()'), self.slot_pushButton_next_clicked)
     39 
     40 
     41     def init_ui_data(self):
     42         self.setPageNum(1)
     43 
     44     def slot_pushButton_jump_clicked(self):
     45         # 获取跳转数据
     46         try:
     47             page_jump_num = self.ui.lineEdit_jump_page.text().toInt()[0]
     48             if page_jump_num > self.total_page or page_jump_num < 1:
     49                 return
     50             self.setPageNum(page_jump_num)
     51             self.emit_page_changed.emit(self.pageRows(), self.pageNum())
     52         except Exception,e:
     53             print str(e)
     54 
     55     def slot_pushButton_per_clicked(self):
     56         '''
     57         上一页
     58         :return:
     59         '''
     60 
     61         pageNum = self.pageNum() - 1
     62 
     63         if pageNum < 0:
     64             return
     65 
     66         self.setPageNum(pageNum)
     67 
     68         self.emit_page_changed.emit(self.pageRows(), self.pageNum())
     69 
     70     def slot_pushButton_next_clicked(self):
     71         '''
     72         下一页
     73         :return:
     74         '''
     75         pageNum = self.pageNum() + 1
     76         if pageNum > self.total_page:
     77             return
     78         self.setPageNum(pageNum)
     79 
     80         self.emit_page_changed.emit(self.pageRows(), self.pageNum())
     81 
     82     def pageRows(self):
     83         '''
     84         获取当前每页显示行数
     85         :return 行数:
     86         '''
     87         pageRows = self.ui.comboBox_show_page_num.currentText().toInt()[0]
     88         if pageRows <= 0:
     89             pageRows = 50
     90         self.page_rows = pageRows
     91         return pageRows
     92 
     93     def pageNum(self):
     94         '''
     95         获取当前显示页数
     96         :return:
     97         '''
     98         return self.page_num
     99 
    100     def setPageNum(self, pageNum):
    101         '''
    102         设置页数
    103         :param pageNum:
    104         :return:
    105         '''
    106         if pageNum <= 0:
    107             pageNum = 1
    108         self.page_num = pageNum
    109         self.ui.lineEdit_jump_page.setText(QString.number(pageNum))
    110 
    111     def setTotalRows(self, total):
    112         '''
    113         设置总行数
    114         :param total:
    115         :return:
    116         '''
    117 
    118         if total < 0:
    119             total = 0
    120 
    121         pagetotal = total/self.page_rows
    122         if (total%self.page_rows) != 0:
    123             pagetotal += 1
    124 
    125         self.total_page = pagetotal
    126 
    127         strPageNum = QString.number(pagetotal)
    128         self.ui.label_total_page_num.setText(strPageNum)
    129 if __name__ == '__main__':
    130     print QString.number(1888)


    一、接收信号:

    
    
    # 接收信号
    self.ui.widget_page.emit_page_changed.connect(self.slot_pageChanged)
    self.ui.widget_list_page.emit_page_changed.connect(self.slot_list_pageChanged)

      




  • 相关阅读:
    SqlDataAdapter 类
    新博开
    gcc编译C++程序

    抖动
    css3 导航效果
    javascript判断IE浏览器的版本
    CSS样式表继承详解
    css选择器
    鼠标样式
  • 原文地址:https://www.cnblogs.com/haoxr/p/5773456.html
Copyright © 2020-2023  润新知