Le 02/12/10 00:32, Ian a écrit :
Hi all,

How can I cause a repaint event on a window that is not the current focus?

When I click on the window it comes to the front, repaints itself and shows the (changed) data correctly.

However in my use case, data shown in the background window, has been updated in another window, and I want to update the background window (without activating it or scribbling on the screen where I shouldn't).  Is this possible?

I'm using PyQt on Windows 7.

Thanks

Ian


_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

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.

--
Vincent V.V.
Oqapy
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to