python - adding QProgress bar within QLineEdit in PyQt or PySide -
hi want add qprogressbar behind qlineedit, in safari browser or ie, here starting point how can hook progressbar , mylineedit when user done entering path progress bar should show progress while path opened !!!
from pyqt4 import qtgui, qtcore import sys class progressbar(qtgui.qprogressbar): """ docstring 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 mylineedit """ def __init__(self, parent=none): super(mylineedit, self).__init__(parent) # want hook bar @ 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()
i looking forward add qcombobox in place of text entered can list other existing folders, not way qcompleter uses though becuase doesnt has of qcombobox, , not want allow user enter doesnt exists.
any appreciated.
i've attached example of qlineedit progress bar behind it. heavily influenced post: http://www.qtcentre.org/threads/54758-progress-bar-form-qlineedit-issue
basically have manage painting yourself. unfortunately didn't seem work when tried same thing qcombobox. suggest posting new question painting progress bar on qcombobox once it!
import sys pyqt4.qtgui import * pyqt4.qtcore import * class mylineedit(qlineedit): def __init__(self, parent=none): qlineedit.__init__(self, parent) self.timer = qbasictimer() self.step = 0 self.doaction() def timerevent(self, e): if self.step >= 100: self.timer.stop() return self.step = self.step + 10 self.repaint() def doaction(self): if self.timer.isactive(): self.timer.stop() else: self.timer.start(1000, self) def generategradient(self, color): gradient = qlineargradient(0, 0, 0, self.height()); m_defaultbasecolor = self.palette().color(qpalette.base) gradient.setcolorat(0, m_defaultbasecolor) gradient.setcolorat(0.15, color.lighter(120)) gradient.setcolorat(0.5, color) gradient.setcolorat(0.85, color.lighter(120)) gradient.setcolorat(1, m_defaultbasecolor) return gradient def paintevent(self, event): p = qpainter(self) panel = qstyleoptionframev2() self.initstyleoption(panel) self.style().drawprimitive(qstyle.pe_panellineedit, panel, p, self) # alternative painting qlineedit when widget has focus , progress bar finished #if self.hasfocus() or self.step >= 100: qlineedit.paintevent(self, event) # i've chosen paint qlineedit.paintevent(self, event) painter = qpainter(self) lenap = qstyleoptionframev2() self.initstyleoption(lenap) backgroundrect = self.style().subelementrect(qstyle.se_lineeditcontents, lenap, self) # alternative if statements might use instead... # # if not self.hasfocus() , self.step < 100: # if self.step < 100: if true: loadingcolor = qcolor(116,192,250) painter.setbrush(self.generategradient(loadingcolor)) painter.setpen(qt.transparent) mid = int(backgroundrect.width()/100.0*self.step) progressrect = qrect(backgroundrect.x(), backgroundrect.y(), mid, backgroundrect.height()) painter.drawrect(progressrect) painter.setpen(qt.solidline) painter.drawtext(backgroundrect, qt.alignleft|qt.alignvcenter, " " + self.text()) class window(qmainwindow): def __init__(self): qmainwindow.__init__(self) self._control = qwidget() self.setcentralwidget(self._control) l = qvboxlayout(self._control) e = mylineedit() l.addwidget(e) b = qpushbutton('a') l.addwidget(b) self.show() if __name__ == '__main__': app = qapplication(sys.argv) ex = window() sys.exit(app.exec_())
Comments
Post a Comment