python - Adjust widths of QHBoxLayout -


here code:

#!/usr/bin/env python3 import sys, time pyside import qtcore, qtgui import base64   # usage: toast('message') class toast(qtgui.qdialog):     def __init__(self, title, msg, duration=2):         qtgui.qdialog.__init__(self)         self.duration = duration         self.title_label = qtgui.qlabel(title)         self.title_label.setalignment(qtcore.qt.alignleft)         self.msg_label = qtgui.qlabel(msg)         self.icon_button = qlabelbutton()         img_b64 = "ivborw0kggoaaaansuheugaaabgaaaaycayaaadgdz34aaaabhncsvqicagifahkiaaaaalwsflzaaaitgaace4bjdea7aaaabl0rvh0u29mdhdhcmuad3d3lmlua3njyxbllm9yz5vupboaaabjdevydenvchlyawdodabqdwjsawmgrg9tywluigh0dha6ly9jcmvhdgl2zwnvbw1vbnmub3jnl2xpy2vuc2vzl3b1ymxpy2rvbwfpbi9zw/7kaaab2eleqvriibwvpw/tubifz7mjtbfsggnuqmabrgpmuyi53pck1iwxuxd2bgyk/godazuq+afilehizuuq/acpryrkgsjpdhkpqx3uok7tjokd7guf57nxh++ljfrvr9e70el03plcbnanh/4t6szlsvdpml5u5duvdabhgdllsj6ajsvd9wfshwhiujzrvgbcrqlb7b6u9aoash6atqdf62ypak6wdibn0wszo52dm9lpezhqs4lhcnhzzj13zj2ttduxjh+z2bgz/zhmjulsapl03r+wtndolus38xj8usww0kcux/f+uzgasnql43i/7nqcwhu/a+cgkfxkhetzaggapsnwsvq8028ielisvcq7ijd0efv6wxzo4l3fzfvcskvy23u/ea2a5knv4dcx5grm9nbdqzfrfacp1huugxmc59zagiljn2awgnwcspcjrfa7owteeatbrqrg3bwqjlkgchzn523gsrnfcdwi+yxkrgejamxms+osonnutukwf9dmwiqpsuys5kmku+vovkzm7kxtzu8a3pwfagb/2iq/m9m9qrtixgbuf4bpjy1qbd8b7cljkryq9kyg/taajb7xzrt9nveuhuk6bhac4etsyrrfr02yfwemblrpqvtfqgaaaabjru5erkjggg=="         pixmap = qtgui.qpixmap()         pixmap.loadfromdata(base64.b64decode(img_b64))         self.icon_button.setpixmap(pixmap)         self.icon_button.resize(20, 20)         self.connect(self.icon_button, qtcore.signal("clicked()"), self.close)          title_layout = qtgui.qvboxlayout()         title_layout.addwidget(self.title_label)         title_layout.addwidget(self.msg_label)         layout = qtgui.qhboxlayout()         layout.addwidget(self.icon_button)         layout.addlayout(title_layout)         self.setgeometry(0, 0, 200, 70)         self.setlayout(layout)          self.setwindowflags(qtcore.qt.framelesswindowhint)         # self.setstylesheet("border: 1px solid red; border-radius: 5px;")         self.toastthread = toastthread(self.duration)         self.toastthread.finished.connect(self.close)         self.toastthread.start()   class toastthread(qtcore.qthread):     def __init__(self, n_seconds):         qtcore.qthread.__init__(self)         self.n_seconds = n_seconds     def run(self):         time.sleep(self.n_seconds)  class qlabelbutton(qtgui.qlabel):     def __init(self, parent):         qlabel.__init__(self, parent)     def mousereleaseevent(self, ev):         self.emit(qtcore.signal('clicked()'))  if __name__ == "__main__":     app = qtgui.qapplication(sys.argv)     program = toast("hi", "there", 10)     program.show()     sys.exit(app.exec_()) 

enter image description here

apparent image label on left taking space. how can fix this?

a horizontal layout give each widget equal amount of space default, can adjust ratio this:

    layout.addwidget(self.icon_button, 1)     layout.addlayout(title_layout, 3) 

so gives title 3 times space icon.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -