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  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PYTHON

PyQT: Getting Started
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 11
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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.



     
     
    >>> More Python Articles          >>> More By A.P.Rajshekhar
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek