這篇文章主要介紹python中pyqt5樹節(jié)點(diǎn)點(diǎn)擊如何實(shí)現(xiàn)多窗口切換問題,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
創(chuàng)新互聯(lián)專業(yè)提供綿陽主機(jī)托管服務(wù),為用戶提供五星數(shù)據(jù)中心、電信、雙線接入解決方案,用戶可自行在線購買綿陽主機(jī)托管服務(wù),并享受7*24小時(shí)金牌售后服務(wù)。具體代碼如下所示:
# 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,]) #設(shè)置分隔條位置 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") # 設(shè)置根節(jié)點(diǎn) root = QTreeWidgetItem(self.tree) root.setText(0, '系統(tǒng)管理') # 設(shè)置樹形控件的列的寬度 #self.tree.setColumnWidth(0, 150) # 設(shè)置子節(jié)點(diǎn)1 child1 = QTreeWidgetItem() child1.setText(0, '增加人員信息') root.addChild(child1) # 設(shè)置子節(jié)點(diǎn)2 child2 = QTreeWidgetItem(root) child2.setText(0, '查詢?nèi)藛T信息') # 加載根節(jié)點(diǎn)的所有屬性與子控件 self.tree.addTopLevelItem(root) # 設(shè)置stackedWidget self.stackedWidget = QStackedWidget(right) # 設(shè)置第一個(gè)面板 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) # 設(shè)置第二個(gè)面板 self.form2 = QWidget() self.formLayout2 = QHBoxLayout(self.form2) self.label2 = QLabel() self.label2.setText("查詢?nèi)藛T信息面板") 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) # 將兩個(gè)面板,加入stackedWidget self.stackedWidget.addWidget(self.form1) self.stackedWidget.addWidget(self.form2) # 樹節(jié)點(diǎn)監(jiān)聽事件 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) == '查詢?nèi)藛T信息': self.on_pushButton2_clicked() else: print('返回主界面') # 按鈕一:打開第一個(gè)面板 def on_pushButton1_clicked(self): self.stackedWidget.setCurrentIndex(0) # 按鈕二:打開第二個(gè)面板 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 點(diǎn)擊按鈕來打開另一個(gè)窗口
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將兩個(gè)窗體關(guān)聯(lián) btn=window.main_ui.pushButton_new btn.clicked.connect(child.show) # 顯示 window.show() sys.exit(app.exec_())
以上是“python中pyqt5樹節(jié)點(diǎn)點(diǎn)擊如何實(shí)現(xiàn)多窗口切換問題”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)頁標(biāo)題:python中pyqt5樹節(jié)點(diǎn)點(diǎn)擊如何實(shí)現(xiàn)多窗口切換問題-創(chuàng)新互聯(lián)
網(wǎng)頁URL:http://jinyejixie.com/article24/dpejce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、網(wǎng)站設(shè)計(jì)公司、關(guān)鍵詞優(yōu)化、外貿(mào)網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容