The code creates a single dialog with QLineEdit
and a QPushButton
.
When the button is clicked I would like the QLineEdit
to turn into a progress bar that would show a progress of the process triggered with the push of the button. When the process is completed the QLineEdit
should get back to its normal “LineEdit” look. How to achieve this?
Here is the Photoshop-ed idea:
A progress bar could be a thin line at the bottom of QLineEdit:
from PyQt4 import QtCore, QtGui
import time
class Dialog(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog .__init__(self, parent)
mainLayout = QtGui.QVBoxLayout()
lineEdit = QtGui.QLineEdit('ITEM 001')
mainLayout.addWidget(lineEdit)
button = QtGui.QPushButton('Push Button')
button.clicked.connect(self.buttonClicked)
mainLayout.addWidget(button)
self.setLayout(mainLayout)
def buttonClicked(self):
print 'button clicked'
for i in range(3):
time.sleep(1)
print '...processing %s'%i
if __name__ == '__main__':
app = QtGui.QApplication([])
window = Dialog()
window.resize(300, 50)
window.show()
app.exec_()
2
Answers
In PyQt4 the
QLinearGradient
gets a horizontal orientation. While PySide it seems handles it like it is a vertical gradient. The code creates aQLineEdit
with its background color set viapalette.setBrush(QPalette.Base, QBrush(QLinearGradient))
. Button push raises the progress bar value by 10%.For PySide where the gradient might be horizontal: