On 02/03/2017 at 07:53, xxxxxxxx wrote:
Using Qt or even Win32 with C4D is not supported because the items are not owned properly by the document. And you have to handle the ownership stuff yourself.
That means (among other things) we can't do things like docking dialogs in the layout.
MAXON can't offer support for this kind of thing.
It's much easier to do it using python using pyQt. Because in C++ we need to compile the moc stuff.
I use an automated system for this. But it would require me to do a full tutorial on it to explain it all.
I thought about doing a tutorial on it once. But the fact is that using Qt this way is a bad hack. And it's really only useful for bragging rights. And it's much better to do things properly using a User Area.
But sometimes it's fun to be a crazy mad scientist and see what you can invent.
Since you've never done it. And you're asking about it.
Here are the instructions for using pyQt with C4D:
DISCLAMER: Never do this in a commercial plugin! This is just for playing mad scientist
NOTE: This is for R13 with python 2.6.
If you're using a newer version that uses 2.7. Download and install the proper pyQt for 2.7 instead
Download the proper PyQt package for you system(32 or 64 bit)
C4d uses python 2.6 so we need to get a PyQt pacakge that runs on that version of python
I only use the 64bit vesion of C4d. So I downloaded this one: PyQt4-4.10-gpl-Py2.6-Qt4.8.4-x64
Install it to a temporary folder on your desktop
Ignore the warning about python not found on your system
Copy and Paste the PyQt4 folder into this folder inside of the c4D folder structure:
C:\Program Files\MAXON\YOUR VERSION\resource\modules\python\res\Python.win64.framework\Lib\site-packages
NOTE:
Make sure you also copy these files too
-sipconfig.py
-sipdistutils.py
-sip.pyd
Uninstall PyQt from ControlPanel->remove programs
We don't want to use it anymore
To use it
In C4D load the module like this:
from PyQt4 import QtGui,QtCore, uic
Here is a small example
#This example creates a Qt dialog with a button in it
#Notice how the constructor's params keeps the dialog as the topmost window
import c4d,sys,time
from PyQt4 import QtGui, QtCore, uic
class Window(QtGui.QWidget) :
def __init__(self) :
QtGui.QWidget.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint)
self.button = QtGui.QPushButton('Test', self)
self.button.clicked.connect(self.handleButton)
layout = QtGui.QVBoxLayout(self)
layout.addStretch(1)
self.setGeometry(300, 300, 300, 150) #Sets the dimensions of the dialog window
layout.addWidget(self.button)
def handleButton(self) :
print ('Hello World')
def main() :
app = QtGui.QApplication(sys.argv)
window = Window()
window.setWindowTitle('My Qt dialog')
window.show()
#sys.exit(app.exec_()) #<---Closes C4D too!!
app.exec_() #Closes the Qt dialog
if __name__=='__main__':
main()
-ScottA