maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   PyQt Stacked Windows Example (https://talk.maemo.org/showthread.php?t=45373)

mymybib 2010-02-21 22:26

PyQt Stacked Windows Example
 
Hi,

somebody could post code example to do Qt Stacked Windows with python ?

I try to do a main window with 4 buttons. Each button must open a new window with 4 more buttons and a back arrow on top right to back to the first windows.

noobmonkey 2010-02-21 22:30

Re: PyQt Stacked Windows Example
 
http://wiki.maemo.org/PyMaemo/UI_tut...ws_and_dialogs
or
http://pymaemo.garage.maemo.org/pyth...onobjects.html

Hope they help......

mymybib 2010-02-22 00:12

Re: PyQt Stacked Windows Example
 
Thanks.

This is better for PyQt :

http://www.friendpaste.com/3ShZGYNMUJQTYHf0lV9LI0

attila77 2010-02-26 10:46

Re: PyQt Stacked Windows Example
 
That's a PySide example (which won't quite work with Qt4.5, even if you convert it to PyQt :) ). For that, I believe you should do something like

myMainWindow = QtGui.QMainWindow()
myStackedWindow = QtGui.QMainWindow(myMainWindow)

mikec 2010-03-22 12:45

Re: PyQt Stacked Windows Example
 
@Atilla77

I got stacked windows working in my main.py like this
(where MainWindow is subclass of QMainWindow)
Code:


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    ui = MainWindow()
    ui.show()
    stackedwindow=MainWindow(ui)
    stackedwindow.show()
    app.exec_()
    sys.exit()

However what I want to do is to trigger a stacked window from a Qt Signal. In my signal handling code the "stackedwindow=MainWindow(ui)" statement does not work as 'ui' variable is out of scope

Any clues how I can parent my stacked window outside of the main.py?

krk969 2010-03-22 12:48

Re: PyQt Stacked Windows Example
 
Quote:

Originally Posted by mikec (Post 577017)
Any clues how I can parent my stacked window outside of the main.py?

I work with C++ not python so I may BS here. :)
Can you not have your stacked window objects created inside your MainWindow or with some sort of Factory.

mikec 2010-03-22 12:59

Re: PyQt Stacked Windows Example
 
Quote:

Originally Posted by krk969 (Post 577022)
I work with C++ not python so I may BS here. :)
Can you not have your stacked window objects created inside your MainWindow or with some sort of Factory.

Thanks @KRK969 that is one option, but it makes a mess of the code, as all of the signal handling code is in one place. If I move it to the main prog, I then get scoping issues with variables the other way round, ie I cant see stuff outside of my main.py (well not easily ).

I'm still learning my Python Parenting skills :D

attila77 2010-03-22 13:29

Re: PyQt Stacked Windows Example
 
I'm not sure I follow... but if you need your 'ui' var in another class, well, then you propagate it through that class' constructor.

Another thing is that with PyQt the signals/slots are evaluated dynamically, i.e. you can connect a (not yet existant) signal to a slot and then emit it later. This is not too pretty and should be avoided if you plan on re-implementing the code in C++, but can save a lot of time if done right.

mikec 2010-03-22 15:51

Re: PyQt Stacked Windows Example
 
Thanks atilla77

Got this all working nicely now. The key was to specify "self" in the call to make the stacked window

here is class definition for my Stacked Window, which contains a couple of buttons and text edit widgets

Code:

class StackedWindow(QtGui.QMainWindow):
    def __init__(self, *args):
        apply(QMainWindow.__init__, (self, ) + args)
        self.setWindowTitle("Stacked Window")
        centralwidget = QtGui.QWidget(self)
        frame = QtGui.QFrame(centralwidget)
        verticalLayout = QtGui.QVBoxLayout(frame)
        pushButton = QtGui.QPushButton("Push Button 1", frame)
        verticalLayout.addWidget(pushButton)
        pushButton_2 = QtGui.QPushButton("Push Button 2", frame)
        verticalLayout.addWidget(pushButton_2)
        lineEdit = QtGui.QLineEdit(frame)
        verticalLayout.addWidget(lineEdit)
        lineEdit_2 = QtGui.QLineEdit(frame)
        verticalLayout.addWidget(lineEdit_2)
        self.setCentralWidget(centralwidget)

and Here is the code that creates the stacked window, when I select an option called "pop" from my main window.

Code:

def on_actionPop_triggered(self):
        stackwindow =StackedWindow(self)
        stackwindow.show()

The key bit was the 'self' in the statement stackwindow=StackedWindow(self) which presumably tells it to attach itself to its Parent and thus become stacked, no need for Hildon.
and you get the nice sliding sideways effect, and the back button on the top right hand corner.


http://farm5.static.flickr.com/4056/...445851f20d.jpg



Now I can finally make a nice config screen for my App:D

noobmonkey 2010-03-22 15:54

Re: PyQt Stacked Windows Example
 
nicely done - will be using this i feel :D :D


All times are GMT. The time now is 23:17.

vBulletin® Version 3.8.8