码迷,mamicode.com
首页 > 其他好文 > 详细

pyqt5窗口跳转

时间:2017-09-08 00:17:45      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:setw   where   fetch   pat   png   pix   qwidget   sage   geometry   

如何在窗体A里点击按钮跳转到窗体B

1、窗体B 的UI文件

 1 # -*- coding: utf-8 -*-
 2 
 3 # Form implementation generated from reading ui file ‘viewTableUi.ui‘
 4 #
 5 # Created by: PyQt5 UI code generator 5.9
 6 #
 7 # WARNING! All changes made in this file will be lost!
 8 
 9 from PyQt5 import QtCore, QtGui, QtWidgets
10 
11 class viewTableUi(object):
12     def setupUi(self, MainWindow):
13         MainWindow.setObjectName("MainWindow")
14         MainWindow.resize(998, 244)
15         self.centralwidget = QtWidgets.QWidget(MainWindow)
16         self.centralwidget.setObjectName("centralwidget")
17         self.viewWidget = QtWidgets.QTableWidget(self.centralwidget)
18         self.viewWidget.setGeometry(QtCore.QRect(0, 0, 991, 192))
19         self.viewWidget.setRowCount(2)
20         self.viewWidget.setColumnCount(10)
21         self.UiStyle()  # 表格样式
22         self.viewWidget.setObjectName("viewWidget")
23         MainWindow.setCentralWidget(self.centralwidget)
24         self.menubar = QtWidgets.QMenuBar(MainWindow)
25         self.menubar.setGeometry(QtCore.QRect(0, 0, 998, 26))
26         self.menubar.setObjectName("menubar")
27         MainWindow.setMenuBar(self.menubar)
28         self.statusbar = QtWidgets.QStatusBar(MainWindow)
29         self.statusbar.setObjectName("statusbar")
30         MainWindow.setStatusBar(self.statusbar)
31 
32         self.retranslateUi(MainWindow)
33         QtCore.QMetaObject.connectSlotsByName(MainWindow)
34 
35     def retranslateUi(self, MainWindow):
36         _translate = QtCore.QCoreApplication.translate
37         MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
38 
39     def UiStyle(self):
40         horizontalHeader = [id,温度,湿度,,,绿,电流,电压,ip,时间]  # 表头内容
41         self.viewWidget.setHorizontalHeaderLabels(horizontalHeader)

2、窗体B数据处理

 1 import sys
 2 import os.path
 3 from PyQt5.QtWidgets import (QMainWindow, QDialog, QWidget, QAction, QHBoxLayout, QVBoxLayout, QGridLayout,  QToolTip,
 4                              QPushButton, QMessageBox, QDesktopWidget, QApplication, QLabel, QTableWidget, QTableWidgetItem,
 5                              QFrame, QComboBox, QAbstractItemView, QHeaderView, QLineEdit)
 6 from PyQt5.QtCore import (QCoreApplication, Qt, QRect, QSize)
 7 from PyQt5.QtGui import (QIcon, QFont, QColor, QBrush, QTextCursor, QPixmap)
 8 from PyQt5 import QtCore, QtGui, QtWidgets
 9 from MysqlHelper import MysqlHelper
10 from viewTableUi import viewTableUi  #引入ui文件
11 import math
12 class viewTable(QMainWindow):
13 
14     def __init__(self,id):
15         super(viewTable, self).__init__()
16         self.tableId=id
17         self.helper = MysqlHelper()
18         # 实例化ui
19         self.viewUi = viewTableUi()
20         self.main()
21 
22     def main(self):
23         self.viewUi.setupUi(self)
24         self.listData(self.tableId)
25         self.show()
26         
27     def listData(self,id):
28         # self.viewUi.viewWidget.setRowCount(0)
29         id=str(id)
30         sql="select * from test where id="+id
31         rs=self.helper.fetchone(sql)
32         for colum_number, data in enumerate(rs):
33             self.viewUi.viewWidget.setItem(0, colum_number, QtWidgets.QTableWidgetItem(str(data)))
34 if __name__ == __main__:
35     app = QApplication(sys.argv)
36     viewTable = viewTable()
37     sys.exit(app.exec_())

3、窗体A内 定义触发按钮方法

1 # 触发新窗口
2 def viewTable(self,id):
3     self.viewTable = viewTable(id)
4     self.viewTable.show()
1 viewBtn.clicked.connect(lambda: self.viewTable(id))

4、效果

技术分享

 

pyqt5窗口跳转

标签:setw   where   fetch   pat   png   pix   qwidget   sage   geometry   

原文地址:http://www.cnblogs.com/yuanlipu/p/7492314.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!