Zetcode PYQT4 Tutorial Layout Management

Source: Internet
Author: User

!/usr/bin/python-*-Coding:utf-8-*-"""Zetcode PYQT4 Tutorial This example shows three labels on a windowusing absolute positioning. Author:jan Bodnarwebsit E:zetcode.com last Edited:october"""ImportSYS fromPyQt4ImportQtguiclassExample (qtgui.qwidget):def __init__(self): Super (Example, self).__init__() Self.initui ()defInitui (self):#The label widget is positioned at x=15 and y=10.LBL1 = Qtgui.qlabel ('Zetcode', self) lbl1.move (15, 10) Lbl2= Qtgui.qlabel ('Tutorials', self) lbl2.move (35, 40) Lbl3= Qtgui.qlabel ('For Programmers', self) lbl3.move (55, 70) Self.setgeometry (300, 300, 250, 150) Self.setwindowtitle ('Absolute') self.show ()defMain (): App=qtgui.qapplication (SYS.ARGV) ex=Example () sys.exit (App.exec_ ())if __name__=='__main__': Main ()--------------------------------------------------------------------------------#!/usr/bin/python#-*-coding:utf-8-*-"""Zetcode PYQT4 Tutorial In this example, we position both pushbuttons in the Bottom-right corner of the window. Author: Jan Bodnarwebsite:zetcode.com last Edited:october"""ImportSYS fromPyQt4ImportQtguiclassExample (qtgui.qwidget):def __init__(self): Super (Example, self).__init__() Self.initui ()defInitui (self):#Here we create both push buttons.OKButton = Qtgui.qpushbutton ("OK") CancelButton= Qtgui.qpushbutton ("Cancel")        #We Create a horizontal box layout and add a stretch factor and both buttons. The stretch adds a stretchable space before the both buttons. This would push them to the right of the window.Hbox =qtgui.qhboxlayout ()#Adds a stretchable space (a qspaceritem) with zero minimum size and stretch factor stretch to the end of this box lay Out.        #Add a spring to fill the spaceHbox.addstretch (1) Hbox.addwidget (okbutton) hbox.addwidget (CancelButton)#to create the necessary layout, we put a horizontal layout into a vertical one. The stretch factor in the vertical box would push the horizontal box with the buttons to the bottom of the window.VBox =qtgui.qvboxlayout ()#Add a spring to fill the spaceVbox.addstretch (1) vbox.addlayout (Hbox)#Finally, we set the main layout of the window.self.setlayout (VBox) self.setgeometry (300, 300, 300, 150) Self.setwindowtitle ('Buttons') self.show ()defMain (): App=qtgui.qapplication (SYS.ARGV) ex=Example () sys.exit (App.exec_ ())if __name__=='__main__': Main ()--------------------------------------------------------------------------------#!/usr/bin/python#-*-coding:utf-8-*-ImportSYS fromPyQt4ImportQtgui"""Zetcode PYQT4 Tutorial In this example, we create a skeletonof a calculator using a QtGui.QGridLayout.author:Jan Bod Narwebsite:zetcode.com last Edited:july"""classExample (qtgui.qwidget):def __init__(self): Super (Example, self).__init__() Self.initui ()defInitui (self):#The instance of a qtgui.qgridlayout is created and set to being the layout for the application window.Grid =qtgui.qgridlayout () self.setlayout (GRID)#These is the labels used later for buttons.names = ['Cls','Bck',"','Close',                 '7','8','9','/',                '4','5','6','*',                 '1','2','3','-',                '0','.','=','+']                #We Create a list of positions in the grid.positions = [(I,J) forIinchRange (5) forJinchRange (4)]                #Buttons is created and added to the layout with the AddWidget () method.         forPosition, nameinchZip (positions, names):ifName = ="':                ContinueButton=Qtgui.qpushbutton (name) grid.addwidget (button,*position) Self.move (300, 150) Self.setwindowtitle ('Calculator') self.show ()defMain (): App=qtgui.qapplication (SYS.ARGV) ex=Example () sys.exit (App.exec_ ())if __name__=='__main__': Main ()--------------------------------------------------------------------------------#!/usr/bin/python#-*-coding:utf-8-*-"""Zetcode PYQT4 Tutorial In this example, we create a bitmore complicated window layout usingthe qtgui.qgridlayout manag Er. Author:jan Bodnarwebsite:zetcode.com last Edited:october"""ImportSYS fromPyQt4ImportQtguiclassExample (qtgui.qwidget):def __init__(self): Super (Example, self).__init__() Self.initui ()defInitui (self): title= Qtgui.qlabel ('Title') Author= Qtgui.qlabel ('Author') Review= Qtgui.qlabel ('Review') Titleedit=qtgui.qlineedit () Authoredit=qtgui.qlineedit () Reviewedit=Qtgui.qtextedit ()#We Create a grid layout and set spacing between widgets.Grid =qtgui.qgridlayout () grid.setspacing (10) Grid.addwidget (title,1, 0) grid.addwidget (titleedit,1, 1) Grid.addwidget (author,2, 0) grid.addwidget (authoredit,2, 1) Grid.addwidget (review,3, 0)#If We add a widget to a grid, we can provide row span and column span of the widget. We make the Reviewedit widget span 5 rows.Grid.addwidget (Reviewedit, 3, 1, 5, 1) self.setlayout (GRID) Self.setgeometry (300, 300, 350, 300) Self.setwindowtitle ('Review') self.show ()defMain (): App=qtgui.qapplication (SYS.ARGV) ex=Example () sys.exit (App.exec_ ())if __name__=='__main__': Main ()

Zetcode PYQT4 Tutorial Layout Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.