这篇文章主要介绍python中pyqt5树节点点击如何实现多窗口切换问题,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
创新互联专业提供绵阳主机托管服务,为用户提供五星数据中心、电信、双线接入解决方案,用户可自行在线购买绵阳主机托管服务,并享受7*24小时金牌售后服务。具体代码如下所示:
# coding=utf-8 import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): hbox = QHBoxLayout(self) left = QFrame(self) # QFrame 控件添加StyledPanel样式能使QFrame 控件之间的界限更加明显 #left.setFrameShape(QFrame.StyledPanel) right = QFrame(self) #right.setFrameShape(QFrame.StyledPanel) splitter1 = QSplitter(Qt.Horizontal) splitter1.addWidget(left) splitter1.setSizes([20,]) #设置分隔条位置 splitter1.addWidget(right) hbox.addWidget(splitter1) self.setLayout(hbox) # 树 self.tree = QTreeWidget(left) self.tree.setStyleSheet("background-color:#eeeeee;border:outset;color:#215b63;") self.tree.setAutoScroll(True) self.tree.setEditTriggers(QAbstractItemView.DoubleClicked | QAbstractItemView.EditKeyPressed) self.tree.setTextElideMode(Qt.ElideMiddle) #self.tree.setIndentation(30) self.tree.setRootIsDecorated(True) self.tree.setUniformRowHeights(False) self.tree.setItemsExpandable(True) self.tree.setAnimated(False) self.tree.setHeaderHidden(True) self.tree.setExpandsOnDoubleClick(True) self.tree.setObjectName("tree") # 设置根节点 root = QTreeWidgetItem(self.tree) root.setText(0, '系统管理') # 设置树形控件的列的宽度 #self.tree.setColumnWidth(0, 150) # 设置子节点1 child1 = QTreeWidgetItem() child1.setText(0, '增加人员信息') root.addChild(child1) # 设置子节点2 child2 = QTreeWidgetItem(root) child2.setText(0, '查询人员信息') # 加载根节点的所有属性与子控件 self.tree.addTopLevelItem(root) # 设置stackedWidget self.stackedWidget = QStackedWidget(right) # 设置第一个面板 self.form1 = QWidget() self.formLayout1 = QHBoxLayout(self.form1) self.label1 = QLabel() self.label1.setText("增加人员信息面板") self.label1.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self.label1.setAlignment(Qt.AlignCenter) self.label1.setFont(QFont("Roman times", 50, QFont.Bold)) self.formLayout1.addWidget(self.label1) # 设置第二个面板 self.form2 = QWidget() self.formLayout2 = QHBoxLayout(self.form2) self.label2 = QLabel() self.label2.setText("查询人员信息面板") self.label2.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self.label2.setAlignment(Qt.AlignCenter) self.label2.setFont(QFont("Roman times", 50, QFont.Bold)) self.formLayout2.addWidget(self.label2) # 将两个面板,加入stackedWidget self.stackedWidget.addWidget(self.form1) self.stackedWidget.addWidget(self.form2) # 树节点监听事件 self.tree.clicked.connect(self.onClicked) # 窗口大化 self.showMaximized() self.setWindowTitle('树窗口分隔案列') self.show() def onClicked(self,qmodeLindex): item=self.tree.currentItem() print('Key=%s,value=%s'%(item.text(0),item.text(1))) if item.text(0) == '增加人员信息': self.on_pushButton1_clicked() elif item.text(0) == '查询人员信息': self.on_pushButton2_clicked() else: print('返回主界面') # 按钮一:打开第一个面板 def on_pushButton1_clicked(self): self.stackedWidget.setCurrentIndex(0) # 按钮二:打开第二个面板 def on_pushButton2_clicked(self): self.stackedWidget.setCurrentIndex(1) if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
ps:下面给大家介绍下python pyqt5 点击按钮来打开另一个窗口
import ui_denglu as dl import ui_zhuche as zc from PyQt5.QtWidgets import QApplication,QMainWindow,QDialog import sys class parentWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.main_ui = dl.Ui_submit_user() self.main_ui.setupUi(self) class childWindow(QDialog): def __init__(self): QDialog.__init__(self) self.child=zc.Ui_MainWindow() self.child.setupUi(self) if __name__=='__main__': app=QApplication(sys.argv) window=parentWindow() child=childWindow() #通过toolButton将两个窗体关联 btn=window.main_ui.pushButton_new btn.clicked.connect(child.show) # 显示 window.show() sys.exit(app.exec_())
以上是“python中pyqt5树节点点击如何实现多窗口切换问题”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!
网页标题:python中pyqt5树节点点击如何实现多窗口切换问题-创新互联
网页URL:https://www.cdcxhl.com/article24/dpejce.html
成都网站建设公司_创新互联,为您提供静态网站、网站设计公司、关键词优化、外贸网站建设、响应式网站、虚拟主机
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联