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  
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: Handling Windows and Buttons
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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: 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
     

       

    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 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek