Python
  Home arrow Python arrow Page 4 - PyQT: Getting Started
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

PyQT: Getting Started
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2006-03-29

    Table of Contents:
  • PyQT: Getting Started
  • PyQT: Understanding the Terminology
  • Steps for PyQT Application Creation
  • PyQT in the Real World

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    PyQT: Getting Started - PyQT in the Real World


    (Page 4 of 4 )

    In real world applications, there would be at least two classes, one that sub-classes a container class such as QDialog and a second that would inherit the first one and set up the QApplication object. For the sake of brevity, in this discussion only one class will be used, that will be derived from the QDialog class. So let's get started.

    First the imports:

    import sys
    from qt import *

    Next the class that derives from QDialog. It is better to derive from QDialog if you require a lightweight application:

    class Form1(QDialog):
    :
    :

    Now the constructor for this class. The main parameters to look out for are the parent indicating the parent of the dialog, the name of the dialog and the flag indicating whether the dialog is modal or not.

    class Form1(QDialog):
      def __init__(self,parent = None,name = None,modal =
    0,fl = 0):
        QDialog.__init__(self,parent,name,modal,fl)
       :
       :

    Next are the two components to be used, QLCDNumber and QSlider. Their objects are instantiated by passing their names and the equivalent of the "this" pointer of C++ - self. Then the geometry is set to set the boundaries:

    class Form1(QDialog):
      def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        QDialog.__init__(self,parent,name,modal,fl)
         self.lCDNumber1 = QLCDNumber(self,"lCDNumber1")
     
       self.lCDNumber1.setGeometry(QRect(110,140,301,30))

         self.slider1 = QSlider(self,"slider1")
         self.slider1.setGeometry(QRect(130,220,261,31))
         self.slider1.setOrientation(QSlider.Horizontal)                                           

         :
         :

    Then connect the QLCDNumber and QSlider. The Signal is "valueChanged" and the slot is "display." Since the display of the QLCDNumber is the receiver and the slot, they are not separately used.

    class Form1(QDialog):
      def __init__(self,parent = None,name = None,modal = 0,fl = 0):
          QDialog.__init__(self,parent,name,modal,fl)
           self.lCDNumber1 = QLCDNumber(self,"lCDNumber1")
           self.lCDNumber1.setGeometry(QRect(110,140,301,30))
                 
           self.slider1 = QSlider(self,"slider1")
           self.slider1.setGeometry(QRect(130,220,261,31))
           self.slider1.setOrientation(QSlider.Horizontal)

         
    self.connect(self.slider1,SIGNAL("valueChanged
    (int)"),  
                       self.lCDNumber1.display)
          :
          :

    Lastly, we have the main section where QApplication will be set up:

    class Form1(QDialog):
      def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        QDialog.__init__(self,parent,name,modal,fl)
         self.lCDNumber1 = QLCDNumber(self,"lCDNumber1")
         self.lCDNumber1.setGeometry(QRect(110,140,301,30))

         self.slider1 = QSlider(self,"slider1")
         self.slider1.setGeometry(QRect(130,220,261,31))
         self.slider1.setOrientation(QSlider.Horizontal)         

         self.connect(self.slider1,SIGNAL("valueChanged(int)"),  
                         self.lCDNumber1.display)

    if __name__ == "__main__":
        a = QApplication(sys.argv)
        QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT
    ("quit()"))
        w = Form1()
        a.setMainWidget(w)
        a.exec_loop()

    That’s all. Whenever the value of the slider changes, the new value is displayed in the  QLCDNumber.

    That brings us to the end of this discussion. It should be evident from the above application how easy it is to develop applications using PyQT. But this is just the beginning. In the future, I will cover other aspects, including complex widgets such as qtcanvas. Till next time.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · PyQT is one of the best toolkits available for Python. In this article I have tried...
       · This tutorial was pretty easy to follow, until the end. Turns out the "w.show()"...
       · But this is maybe the only chance I have to install pyqt in windows...Please tell me...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway