• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 319, comments - 22, trackbacks - 0, articles - 11
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            使用PyQt 制作簡單的啟動界面的例子代碼

            Posted on 2011-05-18 07:37 RTY 閱讀(2927) 評論(0)  編輯 收藏 引用 所屬分類: QtPython
              1#!/usr/bin/env python
              2
              3
              4#############################################################################
              5##
              6## Copyright (C) 2010 Riverbank Computing Limited.
              7## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
              8## All rights reserved.
              9##
             10## This file is part of the examples of PyQt.
             11##
             12## $QT_BEGIN_LICENSE:BSD$
             13## You may use this file under the terms of the BSD license as follows:
             14##
             15## "Redistribution and use in source and binary forms, with or without
             16## modification, are permitted provided that the following conditions are
             17## met:
             18##   * Redistributions of source code must retain the above copyright
             19##     notice, this list of conditions and the following disclaimer.
             20##   * Redistributions in binary form must reproduce the above copyright
             21##     notice, this list of conditions and the following disclaimer in
             22##     the documentation and/or other materials provided with the
             23##     distribution.
             24##   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
             25##     the names of its contributors may be used to endorse or promote
             26##     products derived from this software without specific prior written
             27##     permission.
             28##
             29## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
             30## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
             31## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
             32## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
             33## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
             34## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
             35## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
             36## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
             37## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
             38## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
             39## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
             40## $QT_END_LICENSE$
             41##
             42#############################################################################
             43
             44
             45from PyQt4 import QtCore, QtGui
             46
             47
             48class WidgetGallery(QtGui.QDialog):
             49    def __init__(self, parent=None):
             50        super(WidgetGallery, self).__init__(parent)
             51
             52        self.originalPalette = QtGui.QApplication.palette()
             53
             54        styleComboBox = QtGui.QComboBox()
             55        styleComboBox.addItems(QtGui.QStyleFactory.keys())
             56
             57        styleLabel = QtGui.QLabel("&Style:")
             58        styleLabel.setBuddy(styleComboBox)
             59
             60        self.useStylePaletteCheckBox = QtGui.QCheckBox("&Use style's standard palette")
             61        self.useStylePaletteCheckBox.setChecked(True)
             62
             63        disableWidgetsCheckBox = QtGui.QCheckBox("&Disable widgets")
             64
             65        self.createTopLeftGroupBox()
             66        self.createTopRightGroupBox()
             67        self.createBottomLeftTabWidget()
             68        self.createBottomRightGroupBox()
             69        self.createProgressBar()
             70
             71        styleComboBox.activated[str].connect(self.changeStyle)
             72        self.useStylePaletteCheckBox.toggled.connect(self.changePalette)
             73        disableWidgetsCheckBox.toggled.connect(self.topLeftGroupBox.setDisabled)
             74        disableWidgetsCheckBox.toggled.connect(self.topRightGroupBox.setDisabled)
             75        disableWidgetsCheckBox.toggled.connect(self.bottomLeftTabWidget.setDisabled)
             76        disableWidgetsCheckBox.toggled.connect(self.bottomRightGroupBox.setDisabled)
             77
             78        topLayout = QtGui.QHBoxLayout()
             79        topLayout.addWidget(styleLabel)
             80        topLayout.addWidget(styleComboBox)
             81        topLayout.addStretch(1)
             82        topLayout.addWidget(self.useStylePaletteCheckBox)
             83        topLayout.addWidget(disableWidgetsCheckBox)
             84
             85        mainLayout = QtGui.QGridLayout()
             86        mainLayout.addLayout(topLayout, 0, 0, 12)
             87        mainLayout.addWidget(self.topLeftGroupBox, 1, 0)
             88        mainLayout.addWidget(self.topRightGroupBox, 11)
             89        mainLayout.addWidget(self.bottomLeftTabWidget, 2, 0)
             90        mainLayout.addWidget(self.bottomRightGroupBox, 21)
             91        mainLayout.addWidget(self.progressBar, 3, 0, 12)
             92        mainLayout.setRowStretch(11)
             93        mainLayout.setRowStretch(21)
             94        mainLayout.setColumnStretch(0, 1)
             95        mainLayout.setColumnStretch(11)
             96        self.setLayout(mainLayout)
             97
             98        self.setWindowTitle("Styles")
             99        self.changeStyle('Windows')
            100
            101    def changeStyle(self, styleName):
            102        QtGui.QApplication.setStyle(QtGui.QStyleFactory.create(styleName))
            103        self.changePalette()
            104
            105    def changePalette(self):
            106        if (self.useStylePaletteCheckBox.isChecked()):
            107            QtGui.QApplication.setPalette(QtGui.QApplication.style().standardPalette())
            108        else:
            109            QtGui.QApplication.setPalette(self.originalPalette)
            110
            111    def advanceProgressBar(self):
            112        curVal = self.progressBar.value()
            113        maxVal = self.progressBar.maximum()
            114        self.progressBar.setValue(curVal + (maxVal - curVal) / 100)
            115
            116    def createTopLeftGroupBox(self):
            117        self.topLeftGroupBox = QtGui.QGroupBox("Group 1")
            118
            119        radioButton1 = QtGui.QRadioButton("Radio button 1")
            120        radioButton2 = QtGui.QRadioButton("Radio button 2")
            121        radioButton3 = QtGui.QRadioButton("Radio button 3")
            122        radioButton1.setChecked(True)
            123
            124        checkBox = QtGui.QCheckBox("Tri-state check box")
            125        checkBox.setTristate(True)
            126        checkBox.setCheckState(QtCore.Qt.PartiallyChecked)
            127
            128        layout = QtGui.QVBoxLayout()
            129        layout.addWidget(radioButton1)
            130        layout.addWidget(radioButton2)
            131        layout.addWidget(radioButton3)
            132        layout.addWidget(checkBox)
            133        layout.addStretch(1)
            134        self.topLeftGroupBox.setLayout(layout)    
            135
            136    def createTopRightGroupBox(self):
            137        self.topRightGroupBox = QtGui.QGroupBox("Group 2")
            138
            139        defaultPushButton = QtGui.QPushButton("Default Push Button")
            140        defaultPushButton.setDefault(True)
            141
            142        togglePushButton = QtGui.QPushButton("Toggle Push Button")
            143        togglePushButton.setCheckable(True)
            144        togglePushButton.setChecked(True)
            145
            146        flatPushButton = QtGui.QPushButton("Flat Push Button")
            147        flatPushButton.setFlat(True)
            148
            149        layout = QtGui.QVBoxLayout()
            150        layout.addWidget(defaultPushButton)
            151        layout.addWidget(togglePushButton)
            152        layout.addWidget(flatPushButton)
            153        layout.addStretch(1)
            154        self.topRightGroupBox.setLayout(layout)
            155
            156    def createBottomLeftTabWidget(self):
            157        self.bottomLeftTabWidget = QtGui.QTabWidget()
            158        self.bottomLeftTabWidget.setSizePolicy(QtGui.QSizePolicy.Preferred,
            159                                               QtGui.QSizePolicy.Ignored)
            160
            161        tab1 = QtGui.QWidget()
            162        tableWidget = QtGui.QTableWidget(1010)
            163
            164        tab1hbox = QtGui.QHBoxLayout()
            165        tab1hbox.setMargin(5)
            166        tab1hbox.addWidget(tableWidget)
            167        tab1.setLayout(tab1hbox)
            168
            169        tab2 = QtGui.QWidget()
            170        textEdit = QtGui.QTextEdit()
            171
            172        textEdit.setPlainText("Twinkle, twinkle, little star,\n"
            173                              "How I wonder what you are.\n" 
            174                              "Up above the world so high,\n"
            175                              "Like a diamond in the sky.\n"
            176                              "Twinkle, twinkle, little star,\n" 
            177                              "How I wonder what you are!\n")
            178
            179        tab2hbox = QtGui.QHBoxLayout()
            180        tab2hbox.setMargin(5)
            181        tab2hbox.addWidget(textEdit)
            182        tab2.setLayout(tab2hbox)
            183
            184        self.bottomLeftTabWidget.addTab(tab1, "&Table")
            185        self.bottomLeftTabWidget.addTab(tab2, "Text &Edit")
            186
            187    def createBottomRightGroupBox(self):
            188        self.bottomRightGroupBox = QtGui.QGroupBox("Group 3")
            189        self.bottomRightGroupBox.setCheckable(True)
            190        self.bottomRightGroupBox.setChecked(True)
            191
            192        lineEdit = QtGui.QLineEdit('s3cRe7')
            193        lineEdit.setEchoMode(QtGui.QLineEdit.Password)
            194
            195        spinBox = QtGui.QSpinBox(self.bottomRightGroupBox)
            196        spinBox.setValue(50)
            197
            198        dateTimeEdit = QtGui.QDateTimeEdit(self.bottomRightGroupBox)
            199        dateTimeEdit.setDateTime(QtCore.QDateTime.currentDateTime())
            200
            201        slider = QtGui.QSlider(QtCore.Qt.Horizontal, self.bottomRightGroupBox)
            202        slider.setValue(40)
            203
            204        scrollBar = QtGui.QScrollBar(QtCore.Qt.Horizontal,
            205                self.bottomRightGroupBox)
            206        scrollBar.setValue(60)
            207
            208        dial = QtGui.QDial(self.bottomRightGroupBox)
            209        dial.setValue(30)
            210        dial.setNotchesVisible(True)
            211
            212        layout = QtGui.QGridLayout()
            213        layout.addWidget(lineEdit, 0, 0, 12)
            214        layout.addWidget(spinBox, 1, 0, 12)
            215        layout.addWidget(dateTimeEdit, 2, 0, 12)
            216        layout.addWidget(slider, 3, 0)
            217        layout.addWidget(scrollBar, 4, 0)
            218        layout.addWidget(dial, 3121)
            219        layout.setRowStretch(51)
            220        self.bottomRightGroupBox.setLayout(layout)
            221
            222    def createProgressBar(self):
            223        self.progressBar = QtGui.QProgressBar()
            224        self.progressBar.setRange(0, 10000)
            225        self.progressBar.setValue(0)
            226
            227        timer = QtCore.QTimer(self)
            228        timer.timeout.connect(self.advanceProgressBar)
            229        timer.start(1000)
            230
            231    def getWidget(self, splash):
            232        t = QtCore.QElapsedTimer()
            233        t.start()
            234        while (t.elapsed() < 5000):
            235            str = QtCore.QString("times = "+ QtCore.QString.number(t.elapsed())
            236            splash.showMessage(str)
            237            QtCore.QCoreApplication.processEvents()
            238
            239if __name__ == '__main__':
            240
            241    import sys
            242
            243    app = QtGui.QApplication(sys.argv)
            244
            245    #splash
            246    pixmap = QtGui.QPixmap(u"C:\\Users\\anlin\\Pictures\\13.png")
            247    splash = QtGui.QSplashScreen(pixmap)
            248    label = QtGui.QLabel(splash)
            249    label.setText("<br><br>Foxreal")
            250    label.setAlignment(QtCore.Qt.AlignRight)
            251    splash.show()
            252    QtCore.QCoreApplication.processEvents()
            253
            254    #main window
            255    gallery = WidgetGallery()
            256    splash.finish(gallery.getWidget(splash))
            257    gallery.show()
            258    sys.exit(app.exec_()) 
            259
            久久精品国产一区二区三区不卡| 久久久WWW成人免费精品| 无码人妻久久一区二区三区蜜桃 | 99精品久久精品| 国产成人精品久久亚洲高清不卡| 久久嫩草影院免费看夜色| 国产美女亚洲精品久久久综合| 久久精品蜜芽亚洲国产AV| 久久AⅤ人妻少妇嫩草影院| 亚洲国产精品久久电影欧美| 久久久91精品国产一区二区三区 | 久久国产精品99久久久久久老狼| 精品久久久久久无码中文字幕| 热99RE久久精品这里都是精品免费| 亚洲天堂久久精品| 久久久久久无码Av成人影院| 日韩亚洲国产综合久久久| 色综合久久精品中文字幕首页| 久久精品国产99久久久古代 | 久久天天躁狠狠躁夜夜avapp | 粉嫩小泬无遮挡久久久久久| 久久国产乱子伦精品免费午夜| 国产精品一久久香蕉国产线看观看| 一本综合久久国产二区| 丁香久久婷婷国产午夜视频| 精品久久久久久亚洲| 国产精品久久久久久吹潮| 国产成人精品综合久久久| 亚洲国产天堂久久久久久| 亚洲精品乱码久久久久久蜜桃| 国产精品免费久久久久久久久 | 狠狠色婷婷综合天天久久丁香| 久久99热这里只有精品国产| 久久婷婷色综合一区二区| 国产无套内射久久久国产| 国产高潮国产高潮久久久91 | 久久久亚洲AV波多野结衣| 一本色道久久综合狠狠躁篇| 欧美大战日韩91综合一区婷婷久久青草 | 国产A级毛片久久久精品毛片| 日本福利片国产午夜久久|