python - Qt Widget with slider -


i'm writing gui application using pyqt4 , need create widgets , dialog windows can slided vertically. after clicking "add new widgets" button (and moving down) create dynamically new small widgets (containing 2 textedit objects). want avoid situation when window's height small show widgets obvious solution seems slider. tried use qslider i'm not sure if it's best way , how configure such slider.

class mydialog(qdialog):   def __init__(self, parent=none):     qdialog.__init__(self, parent)     self.smallwidgets = list()      self.resize(450,500)     self.buttonposition = 60      firstwidget = smallwidget(self)     firstwidget.setgeometry(qrect(5,5, 450, 80))      self.addwidgetbutton = qpushbutton(self)     self.addwidgetbutton.settext("add new widget")     self.addwidgetbutton.setgeometry(qrect(165,self.buttonposition,120,40))      self.connect(self.addwidgetbutton, qtcore.signal("clicked()"), self.addnewwidget)     def addnewwidget(self):     newwidget = smallwidget(self)     newwidget.setgeometry(qrect(5,self.buttonposition, 450, 80))     self.buttonposition += 70      newwidget.setvisible(true)     self.smallwidgets.append(newwidget)     self.addwidgetbutton.setgeometry(qrect(165,self.buttonposition,120,40)) 

enter image description here

so took @ekhumoro advice , implemented using layout , qscrollarea (thanks! that's looking for!). scrolling works wanted, suppose implementation not ideal solution. ;)

class mydialog(qdialog):     def __init__(self, strt, parent=none):         qdialog.__init__(self, parent)         self.smallwidgets = list()         self.setminimumwidth(450)         self.setminimumheight(600)          self.setuplayout()         self.setupscrollarea()         self.addwidgetbutton = qpushbutton(self.containerwidget)         self.addwidgetbutton.settext("add new widget")         self.layout.addwidget(self.addwidgetbutton)          self.connect(self.addwidgetbutton, qtcore.signal("clicked()"), self.addnewwidget)      def setuplayout(self):         self.containerwidget = qwidget(self)         self.widgetheight = 120         self.containerwidget.setgeometry(qrect(0,0,450,self.widgetheight))          self.layout = qvboxlayout()         self.containerwidget.setlayout(self.layout)      def setupscrollarea(self):         self.scrollarea = qscrollarea(self)         self.scrollarea.setverticalscrollbarpolicy(qtcore.qt.scrollbarasneeded)         self.scrollarea.sethorizontalscrollbarpolicy(qtcore.qt.scrollbaralwaysoff)         self.scrollarea.setmaximumwidth(440)         self.scrollarea.setminimumheight(600)         self.scrollarea.setwidgetresizable(false)         self.scrollarea.setwidget(self.containerwidget)      def addnewwidget(self):         newwidget = smallwidget(self.containerwidget)         widgetposition = len(self.smallwidgets)         self.layout.insertwidget(widgetposition, newwidget)         self.smallwidgets.append(newwidget)          self.widgetheight += 80         self.containerwidget.resize(450,self.widgetheight) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -