Python
  Home arrow Python arrow Page 3 - PyQT: Handling Windows and Buttons
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 
Actuate Whitepapers 
VeriSign Whitepapers 
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: Handling Windows and Buttons
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2006-04-05

    Table of Contents:
  • PyQT: Handling Windows and Buttons
  • Slots
  • QPushButton
  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    PyQT: Handling Windows and Buttons - QPushButton


    (Page 3 of 4 )

    QPushButton provides a command button or, put more simply, a button. Typical buttons are OK, Cancel, Help, and so on. A QPushButton object can be obtained by calling the constructor with at least two parameters: the parent widget and the label to be displayed. For example, to create an object of QPushButton with the label "Test" and with the  no parent widget, the statement would be:

          test = QPushButton(None,"&Test")

    An ampersand in front of the label marks it as an accelerator key. Or in other words, the letter succeeding the ampersand becomes a hotkey. In the above example, "T" has become a hotkey.

    QPushButton can also display an icon or a pixmap. The icon has to be passed to the QPushButton as a parameter of the constructor, or as a parameter to the setPixmap() or setIconSet() methods of QPushButton class. To make it more clear, take a look at the following example:

          test.setIconSet(QPixmap("Test.xpm"))

    The setIconSet() method requires an object of QPixmap, which in turn takes the name of the graphics file as a parameter. Using the setIconSet() method the icon can be manipulated.

    The next aspect of QPushButton that you need to understand is the events that it can generate, in other words, the signals emitted by QPushButton. QPushButton emits three signals, which are clicked(), pressed(), and released(). Of these, clicked() signal is the most commonly used. The reason for this is that pressed and released together form the click. And most of the time the user expects processing to be done.

    The clicked() signal is emitted when the button is activated. Activation means the button is pressed and released. It is also emitted when the accelerator key is pressed. The pressed() signal is emitted when the button is just pressed, while the released() signal is emitted when a pressed button is released.

    Though all of these are basic events of button widgets, sometimes, capturing the wrong event/signal can be really problematic. For example, if the accept() slot of QDialog is connected with the pressed signal of QPushButton and also with the clicked(), then the clicked()-accept() connection would over-ride the pressed()-accept() connection. So this must to be kept in mind when connecting signals with slots. 

    That brings us to the end of our introduction. In the next section I will put the signals of QPushButton to use in order to demonstrate them in the real world.

    More Python Articles
    More By A.P.Rajshekhar


       · In the second part of the PyQT series I have discussed the two of the most common...
     

       

    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 4 hosted by Hostway