Le 02/12/10 00:32, Ian a écrit :
Hi all,Hi, Exemple : # -*- coding: utf-8 -*- import sys from PyQt4 import QtCore, QtGui class Main(object): def __init__(self, MainWindow): self.centralwidget = QtGui.QWidget(MainWindow) self.colors =['black', 'blue', 'white', 'yellow', 'red'] self.pointer = 0 MainWindow.show() self.create_dialog() def change_background(self): chain = "".join(["QWidget {background-color: ", self.colors[self.pointer], "}"]) self.centralwidget.setStyleSheet(chain) self.pointer += 1 if self.pointer == 5: self.pointer = 0 def create_dialog(self): control = QtGui.QDialog() dialog = Dialog(control, self) control.exec_() class Dialog(object): def __init__(self, Dialog, m): Dialog.setWindowModality(QtCore.Qt.WindowModal) self.main = m self.centralwidget = QtGui.QWidget(Dialog) self.grid = QtGui.QGridLayout(Dialog) self.button = QtGui.QPushButton(Dialog) self.button.setText("Change background") self.grid.addWidget(self.button, 0, 0, 1, 1) self.button.clicked.connect(self.change_color) def change_color(self): self.main.change_background() if __name__ == "__main__": app = QtGui.QApplication(sys.argv) MainWindow = QtGui.QMainWindow() ui = Main(MainWindow) MainWindow.show() sys.exit(app.exec_()) You can also, when the color change, send some datas from Main to Dialog, i.e. one thumbnail that reflect the new appearance of main window. |
_______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
