Python
  Home arrow Python arrow Page 3 - PyQT: Input Widgets
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? 
PYTHON

PyQT: Input Widgets
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2006-11-20


    Table of Contents:
  • PyQT: Input Widgets
  • QCheckBox
  • PyQT in the Real World
  • The Connections
  • The Main Part

  • 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: Input Widgets - PyQT in the Real World
    ( Page 3 of 5 )

    From this part onwards I will be developing a small application spread over several articles. So the first dialog that we need is a host connection panel. In this at present there will be minimal input gathering. At this level only two textboxes, one checkbox and one button, exist. The logic is that both the textboxes will contain default values, and when the first textbox is filled, then the default value in the second textbox will be selected. So here is the code. Keep one thing in mind: this is just skeletal code, so there are no decorations.

    First the imports and defining of the panel:

    from qt import *

    class Form1(QDialog):

        def __init__(self,parent = None,name = None,modal =
    0,fl = 0):

            QDialog.__init__(self,parent,name,modal,fl)

            if not name:

                self.setName("Form1")

    Then creating the labels and the textboxes:

    from qt import *

    class Form1(QDialog):

        def __init__(self,parent = None,name = None,modal = 0,fl = 0):

            QDialog.__init__(self,parent,name,modal,fl)

            if not name:

                self.setName("Form1")

            self.textLabel1 = QLabel(self,"textLabel1")

            self.textLabel1.setGeometry(QRect
    (30,71,111,30))

            self.textLabel1_2 = QLabel(self,"textLabel1_2")

            self.textLabel1_2.setGeometry(QRect
    (30,140,111,30))

           

            self.lineEdit1 = QLineEdit(self,"lineEdit1")

            self.lineEdit1.setGeometry(QRect
    (160,70,181,31))

            self.lineEdit2 = QLineEdit(self,"lineEdit2")

            self.lineEdit2.setGeometry(QRect
    (161,140,180,31))

    Then let's define the checkbox and the pushbuttons.

       class Form1(QDialog):

        def __init__(self,parent = None,name = None,modal = 0,fl =
    0):

            QDialog.__init__(self,parent,name,modal,fl)

            if not name:

                self.setName("Form1")

            self.textLabel1 = QLabel(self,"textLabel1")

            self.textLabel1.setGeometry(QRect(30,71,111,30))

            self.textLabel1_2 = QLabel(self,"textLabel1_2")

            self.textLabel1_2.setGeometry(QRect(30,140,111,30))

            self.lineEdit1 = QLineEdit(self,"lineEdit1")

            self.lineEdit1.setGeometry(QRect(160,70,181,31))

            self.lineEdit2 = QLineEdit(self,"lineEdit2")

            self.lineEdit2.setGeometry(QRect(161,140,180,31))

            self.checkBox1 = QCheckBox(self,"checkBox1")

            self.checkBox1.setGeometry(QRect(30,190,91,21))

            self.pushButton1 = QPushButton
    (self,"pushButton1")

            self.pushButton1.setEnabled(1)

            self.pushButton1.setGeometry(QRect
    (30,230,141,21))

            self.pushButton1_2 = QPushButton
    (self,"pushButton1_2")

            self.pushButton1_2.setEnabled(1)

            self.pushButton1_2.setGeometry(QRect
    (210,230,141,21))

    By now you will be wondering why I have not set the text of the widgets. There is a twist. To enable a multilingual approach, the _tr function can be used. This method, when provided with translation files, can show the captions or the text in the desired language. Here I have placed it in a method called languageChange() which is called after the widgets are placed.

    class Form1(QDialog):

        def __init__(self,parent = None,name = None,modal = 0,fl =
    0):

            QDialog.__init__(self,parent,name,modal,fl)

            if not name:

                self.setName("Form1")

            self.textLabel1 = QLabel(self,"textLabel1")

            self.textLabel1.setGeometry(QRect(30,71,111,30))

            self.textLabel1_2 = QLabel(self,"textLabel1_2")

            self.textLabel1_2.setGeometry(QRect(30,140,111,30))

            self.lineEdit1 = QLineEdit(self,"lineEdit1")

            self.lineEdit1.setGeometry(QRect(160,70,181,31))

            self.lineEdit2 = QLineEdit(self,"lineEdit2")

            self.lineEdit2.setGeometry(QRect(161,140,180,31))

             self.checkBox1 = QCheckBox(self,"checkBox1")

            self.checkBox1.setGeometry(QRect(30,190,91,21))

            self.pushButton1 = QPushButton(self,"pushButton1")

            self.pushButton1.setEnabled(1)

            self.pushButton1.setGeometry(QRect(30,230,141,21))

            self.pushButton1_2 = QPushButton(self,"pushButton1_2")

            self.pushButton1_2.setEnabled(1)

            self.pushButton1_2.setGeometry(QRect(210,230,141,21))

            self.languageChange()

            self.resize(QSize(600,480).expandedTo
    (self.minimumSizeHint()))

            self.clearWState(Qt.WState_Polished)

        def languageChange(self):

            self.setCaption(self.__tr("Form1"))

            self.textLabel1.setText(self.__tr("Host"))

            self.textLabel1_2.setText(self.__tr("Port"))

            self.pushButton1.setText(self.__tr("Submit"))

            self.pushButton1_2.setText(self.__tr("Reset"))

            self.checkBox1.setText(self.__tr("Secured"))

            self.lineEdit1.setText(self.__tr
    ("192.168.1.1"))

            self.lineEdit2.setText(self.__tr("3306"))

        def __tr(self,s,c = None):

            return qApp.translate("Form1",s,c)



     
     
    >>> 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 6 Hosted by Hostway
    Stay green...Green IT