我正在将一些代码从pyGObject迁移到pyQT4,我使用set_progress_fraction作为指示输入值的最大值百分比的方法。
我试图在pyQT4中找到一个等价物,但我失败了。 QLineEdit确实有一个绘画方法,所以这是绘制"绘画的唯一方法。 LineEdit?
- edit-- gtk equiv的例子:
&安培;我现在的pyGObject代码的snippit
def on_entry_change(self,widget,*args):
try:
tmp = float(widget.get_text())
tmp = (tmp- widget.min_bin)/(widget.max_bin - widget.min_bin)
widget.set_progress_fraction(tmp)
except:
return
答案 0 :(得分:0)
我认为您希望将QLineEdit中的值连接到修改进度条的方法。这可能会有所帮助:
from __future__ import division
import sys
from PyQt4.QtCore import (Qt, SIGNAL)
from PyQt4.QtGui import (QApplication, QDialog, QLineEdit,
QVBoxLayout, QProgressBar, QWidget, QLabel)
class Form(QWidget):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.barA = QProgressBar()
self.maximum = 200
self.label1 = QLabel('Maximum = 200')
self.seqM = QLineEdit("num")
layoutO = QVBoxLayout() #set overal layout
layoutO.addWidget(self.label1)
layoutO.addWidget(self.barA)
layoutO.addWidget(self.seqM)
self.setLayout(layoutO)
self.connect(self.seqM, SIGNAL("returnPressed()"), self.updatebar)
def updatebar(self):
try:
currval = float(self.seqM.text())
except:
print 'enter float or integer only'
self.track = (currval/self.maximum)*100
self.barA.setValue(self.track)
app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()`