Python
  Home arrow Python arrow 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
    ( Page 1 of 4 )

    In this article, you will continue to learn about the process of building a GUI in PyQT. Specifically, you will learn about QDialog and QPushButton, which handle windows and buttons, the building blocks of most GUIs.

    Understanding the steps involved in a process in just the first step in the journey of understanding the process. In the first part of PyQT, the first step in understanding the process of building a GUI using PyQT was taken. The journey has just begun.

    In this journey we will be encountering various components starting with the most common widgets (windows, buttons, etc.) and moving on to exquisite widgets (table view, 3d canvas). In this discussion I will be focusing on the most common  ones that become the foundation of a GUI based application: the window and button. In the vocabulary of PyQT they are termed as QWindow (QDialog, QMainWindow, and so on also serve this purpose) and QButton (QPushButton, QRadioButton, and so forth).

    In the first section, I will be discussing QDialog. Then I will cover the main slots and signals of QDialog. In the third section I will discuss QPushButton. Finally, in the last section I will extend the application developed in the previous part to provide the functionalities of changing the display to binary mode, as well as controlling the application window using buttons. That sets the agenda for this discussion.

    QDialog and QPushButton: Gateways to PyQT Applications

    Dialogs and buttons are the most recognized facets of GUI. So how can a toolkit like PyQT be behind? As with all other widgets, it is necessary to know the details in order to tap into their full power. So here are the details.

    First, let's discuss the QDialog class. As you know, windows form the basis of all the GUI-based applications. However there are windows and windows. There is a category of windows that acts as containers for other windows and widgets, such as menus and so on. Then there is a category that acts as a container for simple widgets, and is used for capturing user inputs for a specific process.

    The first category contains the Main Window of an application, and the second category contains the dialog boxes. Though dialog boxes are primarily used to gather user inputs, there are applications that are built completely upon dialog boxes. In this section I will be discussing the attributes, signals and slots that are required more often in building a dialog based application.

    Dialog, by definition, is a window that pops up over the existing application window. The QDialog class is the parent of all the dialog classes. If you remember the "Hello World" application from the first part, the class was derived from QDialog. Now coming back to the QDialog class, it effectively represents the dialogs of real world user interfaces. Since there are two types of dialogs in real world, so the QDialog also supports two types of dialogs, modal and modeless. The important aspect of any type of dialog is that even though it is top level widget, yet it can have a parent.

    Now, let's discuss modal dialogues. If a dialog blocks input to the other widgets, then it is modal.  The most common way to make a dialog modal is by calling its exec_loop() method. The exec_loop() method returns a useful value when the dialog is closed. One other approach is to call the setModal() method with true. But this has to be done before calling the show() method, because once show() is called, setModal() wont have any effect.

    For example, if mDialog is an object of the MDialog class that is derived from QDialog, then:

        mDialog.setModal(true)
      mDialog.show()

        and

        mDialog.exec_loop()

        perform the same function. That is both methods makes the dialog modal.

    As for a modeless dialogue, its functioning is opposite to that of a modal dialog. The best examples of modeless dialog boxes are search/replace dialogs provided by word processors. Dialogs are made modeless by calling the show() method instead of the QDialog class. The show() method doesn't grab the focus from other window elements. Instead it returns to the caller immediately.



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