qt - Writting a custom QPushButton class in Python -
i've started learning pyqt on own , i've come in trouble trying write custom class inherits qpushbutton can adjust attributes. i'm trying pass text argument whenever initialize object of class. pretty sure there's wrong init haven't found yet. here code:
import sys pyside import qtgui, qtcore class mainb(qtgui.qpushbutton): def __init__(text,self, parent = none): super().__init__(parent) self.setupbt(text) def setupbt(self): self.setflat(true) self.settext(text) self.setgeometry(200,100, 60, 35) self.move(300,300) print('chegu aqui') self.settooltip('isso é muito maneiro <b>artur</b>') self.show() class mainwindow(qtgui.qwidget): def __init__(self , parent = none): super().__init__() self.setupgui() def setupgui(self): self.settooltip('oi <i>qwidget</i> widget') self.resize(800,600) self.setwindowtitle('janela artur') af = mainb("bom dia",self) self.show() """ btn = qtgui.qpushbutton('botão',self) btn.clicked.connect(qtcore.qcoreapplication.instance().quit) btn.resize(btn.sizehint()) btn.move(300, 50) """ def main(): app = qtgui.qapplication(sys.argv) ex = mainwindow() sys.exit(app.exec_()) if __name__ == '__main__': main()
you using super in wrong way, super must instance , thing first arg text, that's wrong should self. fixed more , below code should work you
import sys pyside import qtgui, qtcore class mainb(qtgui.qpushbutton): def __init__(self, text, parent = none): super(mainb, self).__init__() self.setupbt(text) def setupbt(self, text): self.setflat(true) self.settext(text) self.setgeometry(200,100, 60, 35) self.move(300,300) print('chegu aqui') self.settooltip('isso muito maneiro <b>artur</b>') self.show() class mainwindow(qtgui.qwidget): def __init__(self , parent = none): super(mainwindow, self).__init__() self.setupgui() def setupgui(self): self.settooltip('oi <i>qwidget</i> widget') self.resize(800,600) self.setwindowtitle('janela artur') newlayout = qtgui.qhboxlayout() af = mainb("bom dia",self) newlayout.addwidget(af) self.setlayout(newlayout) self.show() def main(): app = qtgui.qapplication(sys.argv) ex = mainwindow() sys.exit(app.exec_()) if __name__ == '__main__': main()
Comments
Post a Comment