PyQt4:在QTabWidget的每个选项卡中添加菜单栏

时间:2016-07-05 17:02:44

标签: python pyqt4

我想在每个标签中添加相同的菜单栏。我已经定义了每个选项卡和菜单栏(当前位置很大)。我该怎么做呢?

使用Python 2.7将代码输入Anaconda的iPython笔记本中。

7.4.2016带有Explorer窗口的选项卡

import sys
import webbrowser
from PyQt4 import QtGui, QtCore

class BeginExplorerWidget(QtGui.QTabWidget):
    def __init__(self, parent=None):
        super(BeginExplorerWidget, self).__init__(parent)

        #tab: documentation refering to source datasets      
        info1 = QtGui.QLabel(self)
        info1.setText ("\n\nProQinase Cancer Cell Lines:\nProQinase offers custom-tailored development of cell-based assays and customized generation of stable cell lines.\nInquire about our custom-tailored services and the 310 cell-lines we have in house for completing:\nCellular Phosphorylation, Cell Proliferation, Soft Agar (Clonogenic), Cell Migration, 3D Tumor Spheroid, and Angiogenesis Assays.\n")
        info1.setStyleSheet("font-size: 14px; qproperty-alignment: AlignJustify")
        info2 = QtGui.QLabel(self)
        info2.setText ("\n\nReference Cancer Cell Lines:\nmRNA data was curated from the Cancer Cell Line Encyclopedia (CCLE) and Cancer Genome Project (CGP).\nRevised R code attained from Inconsistency in Large Pharmacogenomic Studies by Haibe-Kains et al., was used as the foundation of analysis.\nUse this section to view published data.")
        info2.setStyleSheet("font-size: 14px; qproperty-alignment: AlignJustify")
        info3 = QtGui.QLabel(self)
        info3.setText ("\n\nPharmacogenomic Data:\nData collected from the ProQinase cell line database along with CCLE and CGP reveal which drugs have been tested on specific cancer cell lines")
        info3.setStyleSheet("font-size: 14px; qproperty-alignment: AlignJustify")
        info4 = QtGui.QLabel(self)
        info4.setText ("\n\nPathway Analysis:\nThis platform is still under development.")
        info4.setStyleSheet("font-size: 14px; qproperty-alignment: AlignJustify")

        icon1 = QtGui.QPixmap('C:\Users\stor0616\Desktop\GUI\ProQinase_Logo_Targeting_Cancer.png')
        icon1_scaled = icon1.scaled(200,100, QtCore.Qt.IgnoreAspectRatio)
        label1 = QtGui.QLabel(self)
        label1.setPixmap(icon1_scaled)
        icon2 = QtGui.QPixmap('C:\Users\stor0616\Desktop\GUI\CCLE.png')
        icon2_scaled = icon2.scaled(200,100, QtCore.Qt.IgnoreAspectRatio)
        label2 = QtGui.QLabel(self)
        label2.setPixmap(icon2_scaled)
        icon3 = QtGui.QPixmap('C:\Users\stor0616\Desktop\GUI\drugs.jpg')
        icon3_scaled = icon3.scaled(200,100, QtCore.Qt.IgnoreAspectRatio)
        label3 = QtGui.QLabel(self)
        label3.setPixmap(icon3_scaled)
        icon4 = QtGui.QPixmap('C:\Users\stor0616\Desktop\GUI\drugs.jpg')
        icon4_scaled = icon4.scaled(200,100, QtCore.Qt.IgnoreAspectRatio)
        label4 = QtGui.QLabel(self)
        label4.setPixmap(icon4_scaled)

        #tab1: ProQinase Cancer Cell Line Explorer

        pushButton1 = QtGui.QPushButton("QPushButton 1")
        pushButton2 = QtGui.QPushButton("QPushButton 2")

        tab = QtGui.QWidget()
        tab1 = QtGui.QWidget()       
        tab2 = QtGui.QWidget()
        tab3 = QtGui.QWidget()
        tab4 = QtGui.QWidget()

        #layouts for including texts
        grid = QtGui.QGridLayout() 
        grid.addWidget(label1, 0,0)
        grid.addWidget(info1, 0,1)
        grid.addWidget(label2, 1,0)
        grid.addWidget(info2, 1,1)
        grid.addWidget(label3, 2,0)
        grid.addWidget(info3, 2,1)
        grid.addWidget(label4, 3,0)
        grid.addWidget(info4, 3,1)

        tab.setLayout(grid) 

        vBoxlayout = QtGui.QVBoxLayout()
        vBoxlayout.addWidget(pushButton1)
        vBoxlayout.addWidget(pushButton2)

        #Set Layout for Third Tab Page
        tab3.setLayout(vBoxlayout)   

        self.addTab(tab, "Documentation")
        self.addTab(tab1,"ProQinase Cancer Cell Lines")
        self.addTab(tab2,"Reference Cancer Cell Lines")
        self.addTab(tab3,"Pharmacogenomic Data")
        self.addTab(tab4, "Pathway Analysis")

        #Main menu
        extractAction = QtGui.QAction("Home", self)
        extractAction.setShortcut("Ctrl+H")
        extractAction.setStatusTip('Return Home')
        extractAction.triggered.connect(self.close_application)
        extractAction1 = QtGui.QAction("Explorer", self)
        extractAction1.setShortcut("Ctrl+E")
        extractAction1.setStatusTip('Enter Explorer')
        extractAction1.triggered.connect(self.close_application)
        extractAction2 = QtGui.QAction("Saved Data", self)
        extractAction2.setShortcut("Ctrl+S")
        extractAction2.setStatusTip('View Saved Data')
        extractAction2.triggered.connect(self.close_application)
        extractAction3 = QtGui.QAction("Export", self)
        extractAction3.setShortcut("Ctrl+X")
        extractAction3.setStatusTip('Export Data')
        extractAction3.triggered.connect(self.close_application)
        extractAction4 = QtGui.QAction("Quit", self)
        extractAction4.setShortcut("Ctrl+Q")
        extractAction4.setStatusTip('Quit PCCLE')
        extractAction4.triggered.connect(self.close_application)
        extractAction5 = QtGui.QAction("Contact", self)
        extractAction5.setShortcut("Ctrl+C")
        extractAction5.setStatusTip('Contact ProQinase Representatives')
        extractAction5.triggered.connect(self.close_application)

        self.mainMenu = QtGui.QMenuBar(self)
        fileMenu = self.mainMenu.addMenu('&File')
        fileMenu.addAction(extractAction)
        fileMenu.addAction(extractAction1)
        fileMenu.addSeparator()
        fileMenu.addAction(extractAction2)
        fileMenu.addAction(extractAction3)
        fileMenu.addAction(extractAction4)
        fileMenu.addSeparator()
        fileMenu.addAction(extractAction5)

        self.show()

    def close_application(self):
        choice = QtGui.QMessageBox.question(self, 'Quit!',
                                           "Are you sure you would like to quit PCCLE?",
                                           QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
        if choice == QtGui.QMessageBox.Yes:
            print("Quitting")
            sys.exit()
        else:
            pass

if __name__ == '__main__':
    app = QtGui.QApplication([])
    window = BeginExplorerWidget()
    window.show()
    app.exec_()

0 个答案:

没有答案