a | b | |
---|
| 0 | + | # Author: Tomi Saarinen, Rohea Oy |
---|
| 0 | + | # License: Do what you feel like but we guarantee nothing. |
---|
| 0 | + | import sys |
---|
| 0 | + | from PySide.QtCore import * |
---|
| 0 | + | from PySide.QtGui import * |
---|
| 0 | + | |
---|
| 0 | + | class StackedWindow(QMainWindow): |
---|
| 0 | + | def __init__(self): |
---|
| 0 | + | QMainWindow.__init__(self) |
---|
| 0 | + | # This attribute makes the whole Stacked Window thing work |
---|
| 0 | + | self.setAttribute(Qt.WA_Maemo5StackedWindow) |
---|
| 0 | + | # Create button and layout |
---|
| 0 | + | self.cw = QWidget(self) |
---|
| 0 | + | self.setCentralWidget(self.cw) |
---|
| 0 | + | self.vbox = QVBoxLayout(self.cw) |
---|
| 0 | + | self.button = QPushButton(self) |
---|
| 0 | + | self.button.setText(QString("Push me")) |
---|
| 0 | + | self.vbox.addWidget(self.button) |
---|
| 0 | + | # Create subwindow |
---|
| 0 | + | self.subWindow = SubWindow(self) |
---|
| 0 | + | # Hide subwindow at first |
---|
| 0 | + | self.subWindow.hide() |
---|
| 0 | + | # Connect button to signal |
---|
| 0 | + | self.connect(self.button, SIGNAL("clicked()"), self.subWindow.show) |
---|
| 0 | + | |
---|
| 0 | + | class SubWindow(QMainWindow): |
---|
| 0 | + | def __init__(self, parent): |
---|
| 0 | + | # Notice that you must give a parent window as parameter to the constuctor |
---|
| 0 | + | QMainWindow.__init__(self, parent) |
---|
| 0 | + | # Also set the Stacked Window parameter for every subwindow in the stack |
---|
| 0 | + | self.setAttribute(Qt.WA_Maemo5StackedWindow) |
---|
| 0 | + | # Just some content... |
---|
| 0 | + | self.label = QLabel(self) |
---|
| 0 | + | self.label.setText(QString("This is a second window in the stack")) |
---|
| 0 | + | self.setCentralWidget(self.label) |
---|
| 0 | + | |
---|
| 0 | + | if __name__ == '__main__': |
---|
| 0 | + | app = QApplication(sys.argv) |
---|
| 0 | + | sw = StackedWindow() |
---|
| 0 | + | sw.show() |
---|
| 0 | + | sys.exit(app.exec_()) |
---|
... | |
---|