Pyqt addition and deletion example (officially provided)

Source: Internet
Author: User

 

######################################## #####################################

##

# Copyright (c) 2010 Hans-Peter Jansen <[email protected]>.

# Copyright (c) 2010 Nokia Corporation and/or its subsidiary (-ies ).

# All Rights Reserved.

##

# This file is part of the examples of pyqt.

##

# $ Qt_begin_license: BSD $

# You may use this file under the terms of the BSD license as follows:

##

# "Redistribution and use in source and binary forms, with or

# Modification, are permitted provided that the following conditions are

# Met:

# * Redistributions of source code must retain the above Copyright

# Notice, this list of conditions and the following disclawing.

# * Redistributions in binary form must reproduce the above Copyright

# Notice, this list of conditions and the following disclawing in

# The documentation and/or other materials provided with

# Distribution.

# * Neither the name of Nokia Corporation and its subsidiary (-ies) nor

# The names of its contributors may be used to endorse or promote

# Products derived from this software without specific prior written

# Permission.

##

# This software is provided by the copyright holders and contributors

# "As is" and any express or implied warranties, including, but not

# Limited to, the implied warranties of merchantability and fitness

# A particle purpose are disclaimed. In no event shall the Copyright

# Owner or contributors be liable for any direct, indirect, incidental,

# Special, exemplary, or consequential damages (including, but not

# Limited to, procurement of substitute goods or services; loss of use,

# Data, or profits; or business interruption) however caused and on any

# Theory of liability, whether in contract, strict liability, or tort

# (Including negligence or otherwise) arising in any way out of the Use

# Of this software, even if advised of the possibility of such damage ."

# $ Qt_end_license $

##

######################################## #####################################

 

 

From pyqt4 import qtgui

 

 

Class window (qtgui. qwidget ):

Def _ init _ (self, parent = none ):

Super (window, self). _ init _ (parent)

 

# Set up the model.

Self. setupmodel ()

 

# Set up the widgets.

Namelabel = qtgui. qlabel ("na & me :")

Nameedit = qtgui. qlineedit ()

Addresslabel = qtgui. qlabel ("& Address :")

Addressedit = qtgui. qtextedit ()

Agelabel = qtgui. qlabel ("A & Ge (in years ):")

Agespinbox = qtgui. qspinbox ()

Self. nextbutton = qtgui. qpushbutton ("& next ")

Self. previusbutton = qtgui. qpushbutton ("& previous ")

Namelabel. setbuddy (nameedit)

Addresslabel. setbuddy (addressedit)

Agelabel. setbuddy (agespinbox)

 

# Set Up The mapper.

Self. mapper = qtgui. qdatawidgetmapper (Self)

Self. Mapper. setmodel (self. Model)

Self. Mapper. addmapping (nameedit, 0)

Self. Mapper. addmapping (addressedit, 1)

Self. Mapper. addmapping (agespinbox, 2)

 

# Set up connections and layouts.

Self. previusbutton. clicked. Connect (self. Mapper. toprevious)

Self. nextbutton. clicked. Connect (self. Mapper. tonext)

Self. Mapper. currentindexchanged. Connect (self. updatebuttons)

 

Layout = qtgui. qgridlayout ()

Layout. addwidget (namelabel, 0, 0, 1, 1)

Layout. addwidget (nameedit, 0, 1, 1, 1)

Layout. addwidget (self. previusbutton, 0, 2, 1, 1)

Layout. addwidget (addresslabel, 1, 0, 1, 1)

Layout. addwidget (addressedit, 1, 1, 2, 1)

Layout. addwidget (self. nextbutton, 1, 2, 1, 1)

Layout. addwidget (agelabel, 3, 0, 1, 1)

Layout. addwidget (agespinbox, 3, 1, 1)

Self. setlayout (layout)

 

Self. setwindowtitle ("simple widget mapper ")

Self. Mapper. tofirst ()

 

Def setupmodel (Self ):

Self. Model = qtgui. qstandarditemmodel (5, 3, self)

Names = ("Alice", "Bob", "Carol", "Donald", "Emma ")

Addresses = ("<QT> 123 Main Street <br/> market town </Qt> ",

"<QT> PO Box 32 <br/> mail handling service"

"<Br/> service city </Qt> ",

"<QT> the lighthouse <br/> remote island </Qt> ",

"<QT> 47338 Park Avenue <br/> big city </Qt> ",

"<QT> Research Station <br/> base camp <br/> big mountain </Qt> ")

Ages = ("20", "31", "32", "19", "26 ")

 

For row, name in enumerate (names ):

Item = qtgui. qstandarditem (name)

Self. model. setitem (row, 0, item)

Item = qtgui. qstandarditem (addresses [row])

Self. model. setitem (row, 1, item)

Item = qtgui. qstandarditem (ages [row])

Self. model. setitem (row, 2, item)

 

Def updatebuttons (self, row ):

Self. previusbutton. setenabled (row> 0)

Self. nextbutton. setenabled (row <self. model. rowcount ()-1)

 

 

If _ name _ = '_ main __':

 

Import sys

 

APP = qtgui. qapplication (SYS. argv)

 

Window = window ()

Window. Show ()

 

Sys.exit(app.exe C _())

 

:

Pyqt addition and deletion example (officially provided)

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.