Hi Alberto,

thank you for your answer!

The event loop is actually running in a separate thread.
I managed to get the example running by adding a call to processEvents:

from PySide import QtGui

from PySide import QtCore

wid = QtGui.QLabel("Whatever")

wid.resize(450, 150)

wid.setWindowTitle('Simple')

wid.show()

while True:

    QtCore.QCoreApplication.processEvents()


I think I will use this workaround for the moment.
It is not clear to me however if this is an expected limitation due to how
Qt works with threads or if this is a bug in PySide.

I would appreciate if someone could come with a cleaner solution or tell me
if I should fill a bug request.

best regards

--
Sébastien Sablé


Le 8 février 2012 15:12, Alberto Soto <[email protected]> a écrit :

> Hi Sébastien,
>
> This sounds to me like an event loop problem.
>
> The MessageBox::question static method creates its own event loop
>  and then returns. So that's probably the reason it works.
>
> Are you creating the QLabel widget in the same thread as the GUI
> application thread? I seem to remember a limitation, when working
>  on multithread Qt applications with a GUI.
>  From the "Rapid GUI Programming with Python and Qt" book:
> PyQt applications always have at least one thread of execution, the primary
> (initial) thread. In addition, they may create as many secondary threads as
> they need. However, if the application has a GUI, the GUI operations, such
> as executing the event loop, may only take place in the primary thread.
> -- chapter 19. Multithreading.
>
> Hope this helps!
>
>
> Alberto SOTO
>
>
> _______________________________________________________________________________________________________
> From: [email protected] [mailto:
> [email protected]] On Behalf Of Sébastien Sablé Sablé
> Sent: mercredi 8 février 2012 11:35
> To: [email protected]
> Subject: [PySide] PySide in a C++ application using Qt
>
> Hi,
>
> I am using PySide 1.1.0. And I would like to use it inside a C++
> application that already uses Qt and provides an embedded Python
> interpreter.
>
> I tried something like that:
>
> from PySide import QtGui
> app = QtGui.QApplication.instance()
> print app
> wid = QtGui.QLabel("Whatever")
> wid.resize(450, 150)
> wid.setWindowTitle('Simple')
> wid.show()
>
>
> Since there is already a running QApplication, I do not create a new one.
> There is also a running event loop in another thread since the application
> interface reacts.
>
> This code snippet works partially:
> a new window is created, with a "simple" title, but the text inside it is
> never displayed and the windows does not react at all:
> I can't move it, resize it or anything.
>
> If I call "wid.repaint()", the text inside the window is correctly
> refreshed; however the window still does not react to any event.
>
> I also tried to create a message box like that:
> QtGui.QMessageBox.question(wid, 'Message', "Existing app: %r" % app,
> QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
>
> This time the message box reacts correctly: it is correctly displayed, it
> shows the existing QApplication object and the buttons react.
>
> A screenshot of the result can be seen here:
> http://dl.free.fr/dey2Tzig3
>
> It seems as if the QLabel I created does not receive any event.
> Do you have any idea of how I can fix that? Should I open a bug concerning
> this behavior?
>
> Thanks in advance
>
> Sébastien Sablé
>
>
>
_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside

Reply via email to