Reply
Thread Tools
Posts: 50 | Thanked: 45 times | Joined on Dec 2009 @ France
#1
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's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#2
http://wiki.maemo.org/PyMaemo/UI_tut...ws_and_dialogs
or
http://pymaemo.garage.maemo.org/pyth...onobjects.html

Hope they help......
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 
Posts: 50 | Thanked: 45 times | Joined on Dec 2009 @ France
#3
Thanks.

This is better for PyQt :

http://www.friendpaste.com/3ShZGYNMUJQTYHf0lV9LI0
 
Posts: 3,319 | Thanked: 5,610 times | Joined on Aug 2008 @ Finland
#4
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)
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 
mikec's Avatar
Posts: 1,366 | Thanked: 1,185 times | Joined on Jan 2006
#5
@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?
__________________
N900_Email_Options Wiki Page
 
krk969's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#6
Originally Posted by mikec View Post
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.
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

“I hear and I forget. I see and I remember. I do and I understand.”
 
mikec's Avatar
Posts: 1,366 | Thanked: 1,185 times | Joined on Jan 2006
#7
Originally Posted by krk969 View Post
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
__________________
N900_Email_Options Wiki Page
 
Posts: 3,319 | Thanked: 5,610 times | Joined on Aug 2008 @ Finland
#8
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.
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 

The Following User Says Thank You to attila77 For This Useful Post:
mikec's Avatar
Posts: 1,366 | Thanked: 1,185 times | Joined on Jan 2006
#9
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.






Now I can finally make a nice config screen for my App
__________________
N900_Email_Options Wiki Page
 

The Following 6 Users Say Thank You to mikec For This Useful Post:
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#10
nicely done - will be using this i feel
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 

The Following User Says Thank You to noobmonkey For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 21:57.