creating object of QtGui.QWidget() throws me out of python iterpreter

249 views
Skip to first unread message

san

unread,
Dec 1, 2012, 1:49:57 AM12/1/12
to python_in...@googlegroups.com
Hello Justine when i try to create object

widget = QGui.QWidget()

i get thrown out of interpreter saying
QWidget: Must construct a QApplication before a QPaintDevice

where as in your first video lecture u didnt got any such error?
                                                                    
In [1]: from PyQt4 import QtGui                                     
                                                                    
In [2]: widget = QtGui.QWidget()                                    
QWidget: Must construct a QApplication before a QPaintDevice        
                                                                    
D:\Console>                                                         
                                                                    
                                                                    

Justin Israel

unread,
Dec 1, 2012, 2:46:11 AM12/1/12
to python_in...@googlegroups.com
Hi,

A QApplication must exist before any QWidget is created.

If you are using ipython to test out PyQt functionality, make sure you are starting ipython like this:
    ipython --gui=qt

As mentioned in my video, this will automatically create your QApplication and start the event loop, so you are free to create widgets right when the interpreter is finished starting up.

If you are running ipython (or just python) without any arguments, then you must do the traditional approach just like any pyqt script:

from PyQt4 import QtCore, QtGui
app = QtGui.QApplication([])

Note, this approach tends to give me terrible hang ups with input to an interactive terminal, which is why I highly recommend ipython --gui=qt for an interactive test session.

-- justin
~ BTW, my name is actually Justin.... Justine would be a girls name ;-) ~



san

unread,
Dec 2, 2012, 9:13:21 AM12/2/12
to python_in...@googlegroups.com
my apologies, don't know i mistyped your name wrong,

I also noticed on windows i didnt needed to use the raise_() the widget or the button showed up just with the call to widget.show()....

Justin Israel

unread,
Dec 2, 2012, 11:42:21 AM12/2/12
to python_in...@googlegroups.com
raise_() is not use to show the widget. It is an extra call after the show() to make sure it pops up to the top of all other windows. This is useful when you have a bunch of windows, and running the main app shows it but it is behind everything:


It is not required at all.

Malcom Armstrong

unread,
Mar 12, 2014, 11:03:00 AM3/12/14
to python_in...@googlegroups.com
I am a windows 7 64 bit user, using Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)]   I have PyQT4 and the rest of the required installs and have been following the CMIVFX tutorial. When I enter the same code as Justin, I get the same error. Have I missed a call to something or is there a different way to get this working?

from PyQt4 import QtGui
widget = QtGui.QWidget()
widget.resize(400,300)
widget.show()
widget.raise_()
#button = QTGui.QpushButton('Button')
#button.show()
#button.raise_()
button = QtGui.QPushButton('Button', parent = widget)
button.show()
button.move(30, 40)


QWidget: Must construct a QApplication before a QPaintDevice

I saw in a lter post that a mac user needed a call to iPython, but I am not using that version.

Thanks
 
      

Justin Israel

unread,
Mar 12, 2014, 2:47:42 PM3/12/14
to python_in...@googlegroups.com

This is a duplicate of the other thread you posted, but ipython is not a requirement. It is available on win/Mac/Linux and just makes it easier to play around with Qt from the command line because it can start the event loop for you.
See other thread for more details.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d2359aed-1c49-437a-a665-6a61608bde6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dillon Bailey

unread,
Mar 12, 2014, 3:13:46 PM3/12/14
to python_in...@googlegroups.com
Thanks so much for sharing this info!
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3U%2BQ%3DOjPLOV9iocXtWZRuM%2BcsdVz%2Be%3DKYx_MZM-CVSwA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages