嗨,我想在QLIneEdit后面添加QProgressBar,就像它在Safari浏览器或IE中一样,所以这里是我的起点,我如何将ProgressBar和MyLineEdit挂在一起,这样当用户输入完路径时,进度条应该显示路径打开时的进度!!!在
from PyQt4 import QtGui, QtCore
import sys
class ProgressBar(QtGui.QProgressBar):
""" docstring for ProgressBar
"""
def __init__(self, parent=None):
super(ProgressBar, self).__init__(parent)
self.timer = QtCore.QBasicTimer()
self.step = 0
self.doAction()
def timerEvent(self, e):
if self.step >= 100:
self.timer.stop()
return
self.step = self.step + 15
self.setValue(self.step)
def doAction(self):
if self.timer.isActive():
self.timer.stop()
else:
self.timer.start(100, self)
class MyLineEdit(QtGui.QLineEdit):
""" docstring for MyLineEdit
"""
def __init__(self, parent=None):
super(MyLineEdit, self).__init__(parent)
# I want to hook this bar at the backgroind of MyLineEdit
pbar = ProgressBar()
class Example(QtGui.QWidget):
def __init__(self, parent=None):
super(Example, self).__init__(parent)
self.pbar = ProgressBar(self)
self.editbx = MyLineEdit(self.pbar)
newPalette = QtGui.QPalette()
newPalette.setColor(self.editbx.backgroundRole(), QtCore.Qt.transparent)
self.editbx.setPalette(newPalette)
self.editbx.setText("Defaukt text set")
self.editbx.setStyleSheet("QLineEdit { border:none;}")
self.pbar.setStyleSheet("QProgressBar {border:none;}")
self.initUI()
def initUI(self):
# self.pbar.setGeometry(30, 40, 200, 25)
self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('QtGui.QProgressBar')
self.show()
def main():
app = QtGui.QApplication(sys.argv)
win = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
我还希望添加一个QCombobox来代替输入的文本,这样它就可以列出其他现有的文件夹,而不是QCompleter使用的方式,因为它没有QCombobox的外观,我不想让用户输入任何不存在的东西。在
任何帮助都将不胜感激。在
我附上了一个QLineEdit的例子,后面有一个进度条。它受到了这个帖子的极大影响:http://www.qtcentre.org/threads/54758-Progress-bar-form-QLineEdit-issue
基本上你得自己动手画画。不幸的是,当我试图用QComboBox做同样的事情时,它似乎不起作用。我建议张贴一个新的问题,特别是画一个QComboBox进度条,一旦你得到它!在
相关问题 更多 >
编程相关推荐