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

pyqt时间

时间:2015-01-04 14:59:37      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

# -*- coding: utf-8 -*-
__author__ = ‘Administrator‘
from PyQt4 import QtCore, QtGui

class Help(QtGui.QMainWindow):
    def __init__(self):
        super(Help, self).__init__()

        #QTimeEdit
        self.TimeEdit = QtGui.QTimeEdit()

        #Hours ScrollBar
        self.HourScrollBar = QtGui.QScrollBar(QtCore.Qt.Horizontal)
        self.HourScrollBar.setMinimum(0)
        self.HourScrollBar.setMaximum(23)
        self.HourScrollBar.setFocusPolicy(QtCore.Qt.StrongFocus)

        #Minutes ScrollBar
        self.MinScrollBar = QtGui.QScrollBar(QtCore.Qt.Horizontal)
        self.MinScrollBar.setMinimum(0)
        self.MinScrollBar.setMaximum(59)
        self.MinScrollBar.setFocusPolicy(QtCore.Qt.StrongFocus)

        #Seconds ScrollBar
        self.SecScrollBar = QtGui.QScrollBar(QtCore.Qt.Horizontal)
        self.SecScrollBar.setMinimum(0)
        self.SecScrollBar.setMaximum(59)
        self.SecScrollBar.setFocusPolicy(QtCore.Qt.StrongFocus)

        #ScrollBar connections
        self.HourScrollBar.valueChanged.connect(self.HourChanged)
        self.MinScrollBar.valueChanged.connect(self.MinChanged)
        self.SecScrollBar.valueChanged.connect(self.SecChanged)

        #Main layout and widget
        MainWidget = QtGui.QWidget()
        MainLayout = QtGui.QVBoxLayout()
        MainLayout.addWidget(self.TimeEdit)
        MainLayout.addWidget(self.HourScrollBar)
        MainLayout.addWidget(self.MinScrollBar)
        MainLayout.addWidget(self.SecScrollBar)
        MainWidget.setLayout(MainLayout)
        self.setCentralWidget(MainWidget)

    def HourChanged(self):
        self.TimeEdit.setTime(QtCore.QTime.fromString(str(self.HourScrollBar.value()), "h"))

    def MinChanged(self):
        self.TimeEdit.setTime(QtCore.QTime.fromString(str(self.MinScrollBar.value()), "m"))

    def SecChanged(self):
        self.TimeEdit.setTime(QtCore.QTime.fromString(str(self.SecScrollBar.value()), "s"))

if __name__ == ‘__main__‘:
    import sys
    app = QtGui.QApplication(sys.argv)
    w = Help()
    w.show()
    sys.exit(app.exec_())

 技术分享

pyqt时间

标签:

原文地址:http://www.cnblogs.com/mhxy13867806343/p/4200922.html

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