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

textChanged(*)重点

时间:2014-09-15 15:47:59      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:io   ar   sp   log   on   c   amp   line   ad   

# -*- coding: cp936 -*-

import sys

from PyQt4 import QtCore, QtGui

 

class MyDialog(QtGui.QDialog):

        def __init__(self, parent=None):

                QtGui.QDialog.__init__(self, parent)

                self.quit = QtGui.QPushButton("Quit")

 

                self.change = QtGui.QPushButton("Change")

                self.change.setEnabled(False)

 

                # funny widget

                self.lcd = QtGui.QLCDNumber(2)

 

                self.slider = QtGui.QSlider(QtCore.Qt.Horizontal)

                self.slider.setRange(0, 99)

                self.slider.setValue(0)

 

                self.lineEdit = QtGui.QLineEdit()

 

                self.connect(self.quit, QtCore.SIGNAL("clicked()"),

                              QtGui.qApp, QtCore.SLOT("quit()"))

                self.connect(self.lineEdit, QtCore.SIGNAL("textChanged(const QString&)"),

                              self.enableChangeButton)

                self.connect(self.slider, QtCore.SIGNAL("valueChanged(int)"),

                              self.SliderChange)

                self.connect(self.change, QtCore.SIGNAL("clicked()"),

                              self.Change)

 

                self.rightLayout = QtGui.QVBoxLayout()

                self.rightLayout.addWidget(self.lineEdit)

                self.rightLayout.addWidget(self.change)

                 

                self.leftLayout = QtGui.QVBoxLayout()

                self.leftLayout.addWidget(self.lcd)

                self.leftLayout.addWidget(self.slider)

                 

                self.layout = QtGui.QHBoxLayout()

                self.layout.addWidget(self.quit)

                self.layout.addLayout(self.leftLayout)

                self.layout.addLayout(self.rightLayout)

                self.setLayout(self.layout);

        def enableChangeButton(self, text):

                self.change.setEnabled(text.isEmpty() == False)#重点

 

        def Change(self):

         value = int(self.lineEdit.text())

         self.lcd.display(value)

         self.slider.setValue(value)

 

        def SliderChange(self):

                value = self.slider.value()

                self.lcd.display(value)

                self.lineEdit.setText(str(value))

 

app = QtGui.QApplication(sys.argv)

dialog = MyDialog()

dialog.show()

sys.exit(app.exec_())

 

textChanged(*)重点

标签:io   ar   sp   log   on   c   amp   line   ad   

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

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