473,785 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PyQt Variables

I have an application I'm writing using PyQt. I'm trying to create the
various windows by subclassing Qt objects. I have a subclassed
QMainWindow as the parent, and then a series of subclassed QWidgets as
other child windows that get used. How can I pass variables back and
forth between the parent and child windows? For example, if I have a
child window that processes a customer lookup I want the retrieved
values to be passed back to the QMainWindow. I have tried using global
variables, but these variables seem to be global only in the sense of
each subclassed object. Not between the subclassed objects.

Here's a generic sample:

parent_window.p y
=============
my_value = 'main'
from child_window import *

class Parent_Window(Q MainWindow):
def __init__(self):
QMainWindow.__i nit__(self,None ,'application main
window',Qt.WDes tructiveClose)
print my_value
child_window= Child_Window()
self.setCentral Widget(child_wi ndow)
self.catchEvent ()

child_window.py
============
class Child_Window(QW idget):
def __init__(self):
QWidget.__init_ _(self)
print my_value

This doesn' t seem to work, as the Child_Window class doesn't recognize
the my_value global variable that appears in the Parent_Window class.

Jan 5 '06 #1
2 5120
gregarican schrieb:
I have an application I'm writing using PyQt. I'm trying to create the
various windows by subclassing Qt objects. I have a subclassed
QMainWindow as the parent, and then a series of subclassed QWidgets as
other child windows that get used. How can I pass variables back and
forth between the parent and child windows? For example, if I have a
child window that processes a customer lookup I want the retrieved
values to be passed back to the QMainWindow. I have tried using global
variables, but these variables seem to be global only in the sense of
each subclassed object. Not between the subclassed objects.


Looks (or better smells) like a design smell to me. In Qt,and especially
PyQt, you rarely subclass widgets, as that makes you lose the
possibility to use the fabulous designer. The only thing I subclass in
PyQt are the designer-generetaed top-level-classes. Can be a widget, or
sometimes dialogs.

QObjects usually communicate using signals/slots. That ensures a nice
weak coupling of components and enforces good MVC design. If you
absolutely must share state by means of instances of widgets,
explicietly introduce them to each other. No globals needed!

Additionally, what you experience is the fact that python only knows
module-global variables. See

http://www.faqs.org/docs/diveintopyt...ct_locals.html

for an introduction.

Regards,

Diez
Jan 5 '06 #2
Diez B. Roggisch wrote:
Looks (or better smells) like a design smell to me. In Qt,and especially
PyQt, you rarely subclass widgets, as that makes you lose the
possibility to use the fabulous designer. The only thing I subclass in
PyQt are the designer-generetaed top-level-classes. Can be a widget, or
sometimes dialogs.

QObjects usually communicate using signals/slots. That ensures a nice
weak coupling of components and enforces good MVC design. If you
absolutely must share state by means of instances of widgets,
explicietly introduce them to each other. No globals needed!
Additionally, what you experience is the fact that python only knows
module-global variables. See
http://www.faqs.org/docs/diveintopyt...ct_locals.html
for an introduction.
Regards,
Diez


Thanks for the reply. Makes perfect sense now that you point this out!

Jan 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2861
by: Ilya Knizhnik | last post by:
Dear All, I am fairly new to Python. I have found it an easy language to learn and a very usefull one for many tasks. Currently I am working on a python project that involves a GUI and it was suggested that PyQt is the best way to design that GUI. However since PyQt is rather new, I have not found much documentation on it, or examples in it. The only useful tutorial/book I have found is at www.opendocspublishing.com/pyqt/ but it is...
2
4221
by: Srinath Avadhanula | last post by:
Hello, I am wondering if QT has something like QWaitForNextEvent() function. This function would block execution of the application till another key was pressed and then return the event which occured. Would like to utlize this in a small application I am building: I am trying to create vi key-bindings for a simple QMultiLineEdit
35
7768
by: Vamsi Mudrageda | last post by:
I am kind of new to Python, and after trying and using wxPython, I found it kind of lacking in easy-to-read documentation, speed at loading, and GUI response-time. So I am looking for an another GUI toolkit that is cross-platform for Python, and am leaning toward PyQt (PyGTK is kind of dull looking in comparison). Unfortunately, although TrollTech says Qt is cross-platform, its license strategy has me a bit confused. So here is to...
8
4853
by: simo | last post by:
OK, so I'm at the stage where I want to make a choice between wxPython and PyQt. Currently I'm using wxPython mainly due to the fact that it has GPL Linux and Windows versions. I prefer Qt to wxWindows, but am confused with all the Windows licensing issues. For the moment this is just for my own tinkering and utility apps, but
10
2210
by: svenn.are | last post by:
Hi, I wanted to run a program that is written in PyQt on my mac, and went over to Riverbank to get PyQ 3.13 and SIP 4.1.1 sources. I followed the installation guide except for the compiling python as Macosx already has python. I had no problem with compiling SIP and also no problem with compiling PyQt nor did I have any error message during make install.
10
3238
by: Michael McGarry | last post by:
Hi, I'm trying to get PyQt up and running under Mac OS X 10.2.8, but can't get past configuring sip. I installed fink's qt3-3.2.3-2 and restarted my shells to get qt3's environment variables QTDIR and QMAKESPEC. I downloaded sip-4.1 from http://www.river-bank.demon.co.uk,
10
2164
by: Simon John | last post by:
After quite a while of wxPython I'm getting back into PyQt, mainly due to the announcement by Trolltech that they will make a GPL version of Qt4 for Windows (and Phil-T said he will make a PyQt to go with it eventually!) I'm currently using PyQt 3.12 that comes with the BlackAdder demo, it seems to work fine with Python 2.3.5 except that it doesn't support the WinXP look'n'feel, the QStyle "WindowsXP" isn't included, and using a...
9
3737
by: Eric Jardim | last post by:
Hi, Is there any site that gather all the documentation about PyQt? The docs of the Riverbank site is poor, and I have found separate tutorials on the net. I know that the Kompany have made a "Qtdoc"-like to PyQt. But it is not free doc.
3
2073
by: Phil Thompson | last post by:
Riverbank Computing is pleased to announce the release of PyQt v4.0beta1 available from http://www.riverbankcomputing.co.uk/pyqt/. PyQt is a comprehensive set of Qt bindings for the Python programming language and supports the same platforms as Qt (Windows, Linux and MacOS/X). Like Qt, PyQt is available under the GPL and a commercial license. PyQt v4 supports Qt v4 (http://www.trolltech.com/products/qt/index.html). PyQt v3 is still...
0
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10152
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.