[PyQt] Fwd: QStandardItem check state
He, Hopefully this helps: from PyQt4.QtCore import * from PyQt4.QtGui import * import sys from random import randint class view(QListView): def __init__(self, parent=None): super(view, self).__init__(parent) model = QStandardItemModel() for n in range(10): item = QStandardItem('Item %s' % randint(1, 100)) check = Qt.Checked if randint(0, 1) == 1 else Qt.Unchecked item.setCheckState(check) item.setCheckable(True) model.appendRow(item) self.setModel(model) self.show() model.itemChanged.connect(self.on_itemChanged) �...@pyqtslot(QStandardItem) def on_itemChanged(self, item): state = ['UNCHECKED', 'TRISTATE', 'CHECKED'][item.checkState()] print "Item with text '%s', is at state %s\n" % ( item.text(), state) if __name__ == '__main__': app = QApplication(sys.argv) widget = view() widget.show() -- Cheers - jamie On Fri, Jun 11, 2010 at 10:59 AM, He Jibo wrote: > Hell, > > I am trying to build a selection tree, as below. I hope to which files are > checked. > > O filename1 > O filename2 > O filename3 > O filename4 > .. > > > I find the following codes fit my need well. But I do not know how to get > the check state signal. I hope, each time an item is checked or unchecked, I > get a state change signal, and find the lists of checked items. > Can someone help me out? Thanks. > > http://stackoverflow.com/questions/846684/a-listview-of-checkboxes-in-pyqt > > > > from PyQt4.QtCore import * > > > from PyQt4.QtGui import * > > > import sys > from random import randint > > > app = QApplication(sys.argv) > > > > model = QStandardItemModel() > > for n in range(10): > > > item = QStandardItem('Item %s' % randint(1, 100)) > > > check = Qt.Checked if randint(0, 1) == 1 else Qt.Unchecked > > > item.setCheckState(check) > item.setCheckable(True) > > > model.appendRow(item) > > > view = QListView() > > > view.setModel(model) > > view.show() > > > app.exec_() > > > > --- > He Jibo > Department of Psychology, > Beckman Institute for Advanced Science and Technology > University of Illinois, Urbana Champaign, > 603 East Daniel St., > Champaign, IL 61820 > website: www.hejibo.info > > > ___ > PyQt mailing list p...@riverbankcomputing.com > http://www.riverbankcomputing.com/mailman/listinfo/pyqt > ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Problem with QTreeWidgetItem clone()
Hi, I have a QTreeWidget which I attempt to copy by: root = treeWidget.topLevelItem(0) clone = root.clone() and I use clone to populate a new QTreeWidget. All the children are there, the problem is that all children have their 'hidden' flags reset. That is, any 'hidden' items in the first tree become visible in the new tree. This of course forces me to iterate over the original tree which negates the usefullness of clone() (at least in this instance). Am I doing something wrong? I kind of assumed a deep copy would preserve things like hidden, selected, etc. Thanks - jamie ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] centrawidget and mainwindow
Ok, I tried to help out here by creating a trivial example, but I seem to have a problem of my own! Here is the example: == from PyQt4 import QtCore, QtGui class MainWindow(QtGui.QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.textEdit1 = QtGui.QPlainTextEdit() self.textEdit1.setPlainText("Text Editor #1") self.textEdit2 = QtGui.QPlainTextEdit() self.textEdit2.setPlainText("Text Editor #2") self.setCentralWidget(self.textEdit1) self.createActions() self.createToolBars() def createActions(self): self.edit1Act = QtGui.QAction(QtGui.QIcon(), "&Editor-1", self, shortcut=QtGui.QKeySequence.New, statusTip="", triggered=self.centralizeEdit1) self.edit2Act = QtGui.QAction(QtGui.QIcon(),"&Editor-2", self, shortcut=QtGui.QKeySequence.Open, statusTip="", triggered=self.centralizeEdit2) def createToolBars(self): self.fileToolBar = self.addToolBar("Central Widget Control") self.fileToolBar.addAction(self.edit1Act) self.fileToolBar.addAction(self.edit2Act) def centralizeEdit1(self): self.setCentralWidget(self.textEdit1) def centralizeEdit2(self): self.setCentralWidget(self.textEdit2) if __name__ == '__main__': import sys app = QtGui.QApplication(sys.argv) mainWin = MainWindow() mainWin.show() sys.exit(app.exec_()) When I run this, it correctly sets Text Edit #1 as Central Widget. Pressing "Editor-2" button correctly changes the Central Widget to Text Edit #2, however, when I press "Editor-1" button to restore Text Edit #1 to Central Widget I get: RuntimeError "underliying C/C++ object has been deleted" Any clues as to what I'm doing wrong??? Thanks - jamie >On Wed, Jan 20, 2010 at 9:14 AM, M Chauhan wrote: > Hi Tabish, > > I would like to replace centralwidget of a mainwindow with another widget > which is created separately. > > For. ex. when I click on a button on mainwindow it should replace the > current centralwidget by a new one. > > Please let me know if you need more info. > > Thanks, > Mrugesh. > > > 2010/1/19 tabish--> >> >> can you please describe ur problem in a better way? >> >> Mrugesh Chauhan wrote: >> > >> > Hello all, >> > >> > Have been trying to find solution to one problem. >> > >> > There's a main window. And there's a widget. Let's call this widget --> >> > widget_new. >> > >> > I would like to replace centralwidget of the mainwindow with the >> > widget_new. >> > >> > >> > setCentralwidget by passing widget_new ( generated by designer) doesn't >> > help. >> > >> > Someone must have come across such a problem. Any leads will be helpful. >> > >> > Thanks, >> > Mru >> > >> > ___ >> > PyQt mailing list p...@riverbankcomputing.com >> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt >> > >> >> -- >> View this message in context: >> http://old.nabble.com/centrawidget-and-mainwindow-tp27212686p27221899.html >> Sent from the PyQt mailing list archive at Nabble.com. >> >> ___ >> PyQt mailing list p...@riverbankcomputing.com >> http://www.riverbankcomputing.com/mailman/listinfo/pyqt > > > ___ > PyQt mailing list p...@riverbankcomputing.com > http://www.riverbankcomputing.com/mailman/listinfo/pyqt > ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] QList / SIP / Python weirdism...
Phil, Ok, got it. All works as you proposed. I guess I'll hide the set/gets behind properties on the python side... Thanks for the quick response! Cheers - jamie On Wed, Dec 16, 2009 at 12:53 PM, Phil Thompson wrote: > On Wed, 16 Dec 2009 11:42:15 -0800, Jamie Riotto > wrote: >> Ok, got my library working with QT classes (thanks Phil!), but I'm seeing >> strange behavior with QList (I can set the list, but not append to >> it). For example I have >> >> Object.h: >> >> Class Object() { >> Public: >> Object(); >> QString name; >> QList testlist; >> }; >> >> >> and Object.sip: >> >> %Import QtCore/QtCoremod.sip >> >> %Module ObjectLib 0 >> >> class Object { >> %TypeHeaderCode >> #include "Object.h" >> %End >> >> public: >> Object(); >> QString name; >> QList testlist; >> >> }; >> >> Everything compiles / links ok (Windows, QT 4.5, SIP 4.6.1) but when I >> run a Python shell I get: >> >> from ObjectLib import * >> >> foo = Object() >> print foo.testlist >> >> foo.testlist.append(7) >> print foo.testlist >> >> foo.testlist = [3,4,5] >> print foo.testlist >> >> foo.testlist[0] = 9 >> print foo.testlist >> >> foo.testlist.pop(0) >> print foo.testlist >> >> = >> Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit >> (Intel)] on win32 >> Type "copyright", "credits" or "license()" for more information. >>>>> >> [ ] >> [ ] >> [3, 4, 5] >> [3, 4, 5] >> [3, 4, 5] >>>>> >> == >> >> >> I.e.the Append, the [ ] index operation and the Pop did not work. Am I >> doing something wrong? > > You can only get and set the values, so... > > l = foo.testlist > l.append(7) > foo.testlist = l > > Phil > ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] QList / SIP / Python weirdism...
Ok, got my library working with QT classes (thanks Phil!), but I'm seeing strange behavior with QList (I can set the list, but not append to it). For example I have Object.h: Class Object() { Public: Object(); QString name; QList testlist; }; and Object.sip: %Import QtCore/QtCoremod.sip %Module ObjectLib 0 class Object { %TypeHeaderCode #include "Object.h" %End public: Object(); QString name; QList testlist; }; Everything compiles / links ok (Windows, QT 4.5, SIP 4.6.1) but when I run a Python shell I get: from ObjectLib import * foo = Object() print foo.testlist foo.testlist.append(7) print foo.testlist foo.testlist = [3,4,5] print foo.testlist foo.testlist[0] = 9 print foo.testlist foo.testlist.pop(0) print foo.testlist = Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> [ ] [ ] [3, 4, 5] [3, 4, 5] [3, 4, 5] >>> == I.e.the Append, the [ ] index operation and the Pop did not work. Am I doing something wrong? Thanks for the help - jamie ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Unable to find file "QtCore/QtCoremod.sip"...
I'm on Windows using Python 2.5, PyQt-win-gpl-4.6.1, sip-4.9.1 and Qt 4.5.2. I have a working graphics primative library that I wrap with SIP. I'd like to add Qt classes to my library, e.g. QString. I've added: %Import QtCore/QtCoremod.sip to my sip file, but I get the error: sip: Unable to find file "QtCore/QtCoremod.sip" (I get the same error when I try %import PyQt4/QtCore/QtCoremod.sip) I see QtCoremod.sip at: c:\Python25\sip\PyQt4\QtCore\QtCoremod.sip Any help? Thanks - jamie ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Problems with accessing embedded python objects in QT App
I am trying to constuct a simple empbedded Python app. Basically it is a MainWindow with two widgets in its central layout. The left widget is an openGL Viewer, and the right widget is a QTextEdit whose text is sent to a python interpreter upon a button push. My app is linked with a static c++ lib of graphic primatives, like constuct a cube and so on, which I've also wrapped with SIP and have generated a GraphicPrimatives.pyd file. When I run my app, I import the GraphicPrimatives.pyd file into my python interpreter and create a graphics object (no problem), and I'd like to display the graphics object on the openGL side. At first, I assumed that both the c++ side and the python side would point to the same library instantiation, but that appears not to be the case. For instance, I created a singleton class in the graphics library. If I call the singleton class from the C++ side, I see correct initialization, but if I then call the singleton class from the python side, I get a 2nd initialization (i.e. they are not pointing back to the same static object in memory). So my question is: 1) How do I fix the library problem above (i.e. how do I have both the c++ and python interpreter pointing to the same library. or 2) How do I pass or fetch a pointer to the object in python space? I've tried using something like Py_Initialize(); PyRun_SimpleString("from GraphicPrimatives import *"); PyRun_SimpleString("rootObject = Object()"); PyObject* mainModule = PyImport_AddModule("__main__"); pyDict = PyModule_GetDict(mainModule); PyObject* pyRootObject = PyDict_GetItemString(pyDict, "rootObject"); But simply trying to cast the pointer like: (Object *)pyRootObject produced incorrect results. Any help would be greatly appreciated. Thanks - Jamie Riotto ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Passing Tuple through SIP...
I have a vector class whose .h is: class Vec3 { public: float x; float y; float z; public: Vec3():x(0.0),y(0.0),z(0.0) {} Vec3(float X,float Y,float Z):x(X),y(Y),z(Z) {} Vec3(const Vec3& v) {x=v[0];y=v[1];z=v[2];} Vec3(const float v[]) {x=v[0];y=v[1];z=v[2];} }; The corresponding SIP file is: class Vec3 { %TypeHeaderCode #include "Vec3.h" %End public: float x; float y; float z; Vec3(); Vec3(float x,float y,float z); Vec3(const Vec3& v2); //Vec3(const float v2[]); }; Two Issues: 1) I can't get the Vec(const float v[]) constructor to compile on SIP. I assume that's because I can't pass a pointer from Python? So, perhaps the answer is there is no equivalent for this on the python side, so leaving this out of the sip file is correct. But then, 2) What I really want is to be able to say on the python side is: from Vec3 import * t = (1,2,3) # or t = [1,2,3] v = Vec3(t) I'm confused as to how to go about this, as I can't declare a type Tuple in a C++ declaration. Any help would be appreciated. Thanks - jamie ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Compiler Error using SIP: error C3861: 'PyUnicode_FromFormat': identifier not found
Phil, Thanks for the pointer. It looks like PyUnicode_FromFormat() was added in Python 3.0, and I missed the following lines in QPoint.h which explains that: #if PY_MAJOR_VERSION >=3 PyUnicode_FromFormat #else PyString_FromFormat Now I just have to work around the fact that PyString doesn't support conversion to floats! (Looks like that is fixed in 3.0 also...) Thanks, back to compiling - jamie On Mon, Oct 26, 2009 at 1:05 AM, Phil Thompson wrote: > On Sun, 25 Oct 2009 14:45:44 -0700, Jamie Riotto > wrote: >> Hi, >> I'm trying to learn to use SIP, and I've started out with a simple >> Vector class. The sip file looks like this: >> >> > === >> %Module Vec3 0 >> >> class Vec3 { >> >> %TypeHeaderCode >> #include "Vec3.h" >> %End >> >> public: >> >> float x; >> float y; >> float z; >> >> Vec3(); >> Vec3(float xpos,float ypos,float zpos); >> float getX(); >> float getY(); >> float getZ(); >> SIP_PYOBJECT __repr__() const; >> %MethodCode >> sipRes = PyUnicode_FromFormat("Vec3(%f, %f, %f)", sipCpp->getX(), >> sipCpp->getY(), sipCpp->getZ()); >> %End >> }; >> >> > == >> >> The __repr__ section is my frist attempt at implementing python >> functions (operators next). I've used QPoint.h and QPoint.sip >> as my starting point. The c++ code compiles ok , but when I try to >> compile SIP with the following makefile, >> >> I get the following error: >> >> sipvec3Vec3.cpp >> vec3.sip(26): error C3861: 'PyUnicode_FromFormat': identifier not found >> >> Any suggestions? Thanks - jamie > > If you look up PyUnicode_FromFormat() in the Python docs you will see that > there is no such function. > > There is PyUnicode_Format() but make sure you call it properly. > > Phil > ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Compiler Error using SIP: error C3861: 'PyUnicode_FromFormat': identifier not found
Hi, I'm trying to learn to use SIP, and I've started out with a simple Vector class. The sip file looks like this: === %Module Vec3 0 class Vec3 { %TypeHeaderCode #include "Vec3.h" %End public: float x; float y; float z; Vec3(); Vec3(float xpos,float ypos,float zpos); float getX(); float getY(); float getZ(); SIP_PYOBJECT __repr__() const; %MethodCode sipRes = PyUnicode_FromFormat("Vec3(%f, %f, %f)", sipCpp->getX(), sipCpp->getY(), sipCpp->getZ()); %End }; == The __repr__ section is my frist attempt at implementing python functions (operators next). I've used QPoint.h and QPoint.sip as my starting point. The c++ code compiles ok , but when I try to compile SIP with the following makefile, I get the following error: sipvec3Vec3.cpp vec3.sip(26): error C3861: 'PyUnicode_FromFormat': identifier not found Any suggestions? Thanks - jamie TARGET = vec3.pyd OFILES = sipvec3cmodule.obj sipvec3Vec3.obj HFILES = sipAPImesh.h CC = cl CXX = cl LINK = link CPPFLAGS = -DNDEBUG -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -I. -I.. -Ic:\python25\include -Ic:\python25\sip CFLAGS = -nologo -Zm200 -Zc:wchar_t- -O2 -MD -W3 CXXFLAGS = -nologo -Zm200 -Zc:wchar_t- -O2 -MD -W3 -w34100 -w34189 LFLAGS = /NOLOGO /DLL /MANIFEST /MANIFESTFILE:$(TARGET).manifest /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /INCREMENTAL:NO LIBS = /LIBPATH:c:\python25\libs ..\lib\vec3.lib c:\python25\site_packages .SUFFIXES: .c .cpp .cc .cxx .C {.}.cpp{}.obj:: $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -Fo @<< $< << {.}.cc{}.obj:: $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -Fo @<< $< << {.}.cxx{}.obj:: $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -Fo @<< $< << {.}.C{}.obj:: $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -Fo @<< $< << {.}.c{}.obj:: $(CC) -c $(CFLAGS) $(CPPFLAGS) -Fo @<< $< << all: $(TARGET) $(OFILES): $(HFILES) $(TARGET): $(OFILES) $(LINK) $(LFLAGS) /OUT:$(TARGET) @<< $(OFILES) $(LIBS) << mt -nologo -manifest $(TARGET).manifest -outputresource:$(TARGET);2 install: $(TARGET) @if not exist c:\python25\Lib\site-packages mkdir c:\python25\Lib\site-packages copy /y $(TARGET) c:\python25\Lib\site-packages\$(TARGET) clean: -del $(TARGET) -del sipveccmodule.obj -del sipvecVec3.obj -del $(TARGET).manifest === ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Trying to build pyQGLViewer...
Ok, after two weeks, I'm still stuck. I get the same error whether I compile the stack with mingw or Visual Studio 2008, and whether I use Python25 or Python26. It looks like a Qt Macro is missing, but I'm not sure. The problem is in libQGLViewer/QGLViewer/domUtils.h: #if QT_VERSION > 0x04 # include # include # include # include # include #else # include # include # include # include # include #endif Since Qt is 4.5.2 the upper includes are used. They appear to be macro's rather than filenames. Clearly, they are correctly handled when libQGLViewer is built. But when I go into pyQGLViewer and type "python configur.py" and "nmake" I get: Found SIP-4.9-snapshot-20090821. Found 'nt' operating system: Found Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] Found libQGLViewer-2.3.4 in 'C:\Python25\Lib\site-packages\libQGLViewer-2.3.4'. Setup the qglviewer package build. 0 file(s) lazily copied. Listing build ... Setup the PyQGLViewer build. Great, run make or nmake to build and install PyQGLViewer. cd build "c:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\nmake.exe" cl -c -nologo -Zm200 -Zc:wchar_t- -O2 -MD -W3 -w34100 -w34189 -DNDEBUG -DWIN32 -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_XML_LIB -DQT_CORE_LIB -DQT_GUI_LIB -I. -IC:\Python25\Lib\site-packages\libQGLViewer-2.3.4 -Ic:\python25\include -IC:\Qt\4.5.2-msvc2008\mkspecs\default -IC:\Qt\4.5.2-msvc2008\include\QtOpenGL -IC:\Qt\4.5.2-msvc2008\include\QtXml -IC:\Qt\4.5.2-msvc2008\include\QtCore -IC:\Qt\4.5.2-msvc2008\include\QtGui -IC:\Qt\4.5.2-msvc2008\include -Fo @C:\DOCUME~1\JAMIE~1.TRE\LOCALS~1\Temp\nm11.tmp sipPyQGLViewercmodule.cpp C:\Python25\Lib\site-packages\libQGLViewer-2.3.4\QGLViewer/domUtils.h(25) : fatal error C1083: Cannot open include file: 'QGlobal': No such file or directory sipPyQGLViewerDomUtils.cpp C:\Python25\Lib\site-packages\libQGLViewer-2.3.4\QGLViewer/domUtils.h(25) : fatal error C1083: Cannot open include file: 'QGlobal': No such file or directory Generating Code... Any Help?? ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Problems building PyQGLVIewer
I'm trying to use PyQGLViewer on top of PyQt. I'm using Win XP with Visual Studio 2008 C++ and have installed: Python-2.5.4.msi QT Opensourse 4.5.2 SIP-4.9-snapshot-20090821 QScintilla-gpl-2.4.1-snapshot-20090819 PyQt-win-gpl-4.5.4 libQGLViewer-2.3.3 All examples work in Qt, PyQt and LibQGLViewer. However, when I download PyQGLVIewer-0.7.zip and try python configure.py nmake I get the following error: cd build "c:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\nmake.exe" cl -c -nologo -Zm200 -Zc:wchar_t- -O2 -MD -W3 -w34100 -w34189 -DNDEBUG -DWIN32 -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_XML_LIB -DQT_CORE_LIB -DQT_GUI_LIB -I. -IC:\Python25\Lib\site-packages\libQGLViewer-2.3.4 -Ic:\python25\include -IC:\Qt\4.5.2-msvc2008\mkspecs\default -IC:\Qt\4.5.2-msvc2008\include\QtOpenGL -IC:\Qt\4.5.2-msvc2008\include\QtXml -IC:\Qt\4.5.2-msvc2008\include\QtCore -IC:\Qt\4.5.2-msvc2008\include\QtGui -IC:\Qt\4.5.2-msvc2008\include -Fo @C:\DOCUME~1\JAMIE~1.TRE\LOCALS~1\Temp\nmE4A.tmp sipPyQGLViewercmodule.cpp C:\Python25\Lib\site-packages\libQGLViewer-2.3.4\QGLViewer/domUtils.h(25) : fatal error C1083: Cannot open include file: 'QGlobal': No such file or directory sipPyQGLViewerDomUtils.cpp C:\Python25\Lib\site-packages\libQGLViewer-2.3.4\QGLViewer/domUtils.h(25) : fatal error C1083: Cannot open include file: 'QGlobal': No such file or directory Generating Code... Interestingly, I get exactly the same message when I follow all the above steps with Python 2.6.2... Any ideas? Thanks very much - Jamie Riotto ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] QTreeWidget and item parents
Scott, simply do: print self.theTree.currentItem().text(0) index = self.theTree.currentIndex() print "row: ", index.row()# returns row number relative to branch parent NEW>>>print "parent", index.parent() Cheers - jamie On Thu, Aug 27, 2009 at 8:46 AM, Scott Frankel wrote: > > Hello, > > How would one identify the parent of a selected item in a QTreeWidget? > > I have a tree with several branches. Each branch contains leaves with the > same names. (See attached sample code.) I'd like to be able to identify > that the leave item selected, say "Bbbb," was picked from branch "Three." > > I'm identifying the selected leaf item with currentItem(). (See line 126 in > pickItem()). The currentIndex() method returns indeces that appear to be > relative to the leaf's parent, which in this case doesn't help me identify > which branch item is the selected item's parent. > > Thanks in advance! > Scott > > > > > > > > > > ___ > PyQt mailing list p...@riverbankcomputing.com > http://www.riverbankcomputing.com/mailman/listinfo/pyqt > ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Looking for signal from QTreeView
I have a QTreeView that allows internal moves and drags & drops. I have no problem getting a signal when an item is selected or edited, but I can't figure out how to catch a signal when a drag-and-drop has made one item in the tree a child of another item. Any suggestions? Thanks - Jamie Riotto ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Help about the use of OpenGL with PyQt
OpenGL Tutorial: http://cs.uccs.edu/~semwal/indexGLTutorial.html Also NeHe productions does a realy great job breaking down OpenGL into "lessons": My favorite! http://nehe.gamedev.net/ Also, since your accessing OpenGL through PyOpenGL, you should look at: http://pyopengl.sourceforge.net/documentation/ for other links and examples. Enjoy - jaime On Sat, Apr 4, 2009 at 9:35 AM, projetmbc wrote: > >>> Your problem is with your OpenGL syntax. Simply change GL.GL_QUADS > (which draw quadrilaterals) with GL.GL_TRIANGLES (self evident). Also, it > would be better to move those declarations into your triangle routine as > follows > > Thanks and sorry for this simple problem but I'm a real newbie with OpenGL. > > Where can I find documentations showing what kind of objects I can draw > with OpenGL ? > > Best regards and thanks a lot. > > > > ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Help about the use of OpenGL with PyQt
Christophe, Your problem is with your OpenGL syntax. Simply change GL.GL_QUADS (which draw quadrilaterals) with GL.GL_TRIANGLES (self evident). Also, it would be better to move those declarations into your triangle routine as follows: def triangle(self, x1, y1, z1, x2, y2, z2, x3, y3, z3,r,g,b): self.qglColor(QtGui.QColor(r,g,b)) GL.glBegin(GL.GL_TRIANGLES) GL.glVertex3d(x1, y1, z1) GL.glVertex3d(x2, y2, z2) GL.glVertex3d(x3, y3, z3) GL.glEnd() This way, each glBegin is guaranteed to have a closing glEnd. I believe it now works as you would expect... Cheers - jamie On Sat, Apr 4, 2009 at 9:04 AM, projetmbc wrote: > Hello, > I would like to draw for example a 3D triangle with OpenGL. I've tried to > play with the example Hello GL proposed by PyQt. > > In the following code I would like to draw a red triangle and then a blue > one. I also would like to set the xMin, xMax, yMin, yMax, zMin, zMax, for > the point of view. My purpose would be to a 3D geometric viewers for > educational purposes. > > Best regards. > Christophe > > > The code > > > #!/usr/bin/env python > > """PyQt4 port of the opengl/hellogl example from Qt v4.x""" > > import sys > import math > from PyQt4 import QtCore, QtGui, QtOpenGL > > try: > from OpenGL import GL > except ImportError: > app = QtGui.QApplication(sys.argv) > QtGui.QMessageBox.critical(None, "OpenGL hellogl", > "PyOpenGL must be installed to run this > example.", > QtGui.QMessageBox.Ok | QtGui.QMessageBox.Default, > QtGui.QMessageBox.NoButton) > sys.exit(1) > > > class Window(QtGui.QWidget): > def __init__(self, parent=None): > QtGui.QWidget.__init__(self, parent) > > self.glWidget = GLWidget() > > self.xSlider = > self.createSlider(QtCore.SIGNAL("xRotationChanged(int)"), >self.glWidget.setXRotation) > self.ySlider = > self.createSlider(QtCore.SIGNAL("yRotationChanged(int)"), >self.glWidget.setYRotation) > self.zSlider = > self.createSlider(QtCore.SIGNAL("zRotationChanged(int)"), >self.glWidget.setZRotation) > > mainLayout = QtGui.QHBoxLayout() > mainLayout.addWidget(self.glWidget) > mainLayout.addWidget(self.xSlider) > mainLayout.addWidget(self.ySlider) > mainLayout.addWidget(self.zSlider) > self.setLayout(mainLayout) > > self.xSlider.setValue(15 * 16) > self.ySlider.setValue(345 * 16) > self.zSlider.setValue(0 * 16) > > self.setWindowTitle(self.tr("Hello GL")) > > def createSlider(self, changedSignal, setterSlot): > slider = QtGui.QSlider(QtCore.Qt.Vertical) > > slider.setRange(0, 360 * 16) > slider.setSingleStep(16) > slider.setPageStep(15 * 16) > slider.setTickInterval(15 * 16) > slider.setTickPosition(QtGui.QSlider.TicksRight) > > self.glWidget.connect(slider, QtCore.SIGNAL("valueChanged(int)"), > setterSlot) > self.connect(self.glWidget, changedSignal, slider, > QtCore.SLOT("setValue(int)")) > > return slider > > > class GLWidget(QtOpenGL.QGLWidget): > def __init__(self, parent=None): > QtOpenGL.QGLWidget.__init__(self, parent) > > self.object = 0 > self.xRot = 0 > self.yRot = 0 > self.zRot = 0 > > self.lastPos = QtCore.QPoint() > > self.trolltechGreen = QtGui.QColor.fromCmykF(0.40, 0.0, 1.0, 0.0) > self.trolltechPurple = QtGui.QColor.fromCmykF(0.39, 0.39, 0.0, 0.0) > > def xRotation(self): > return self.xRot > > def yRotation(self): > return self.yRot > > def zRotation(self): > return self.zRot > > def minimumSizeHint(self): > return QtCore.QSize(50, 50) > > def sizeHint(self): > return QtCore.QSize(400, 400) > > def setXRotation(self, angle): > angle = self.normalizeAngle(angle) > if angle != self.xRot: > self.xRot = angle > self.emit(QtCore.SIGNAL("xRotationChanged(int)"), angle) > self.updateGL() > > def setYRotation(self, angle): > angle = self.normalizeAngle(angle) > if angle != self.yRot: > self.yRot = angle > self.emit(QtCore.SIGNAL("yRotationChanged(int)"), angle) > self.updateGL() > > def setZRotation(self, angle): > angle = self.normalizeAngle(angle) > if angle != self.zRot: > self.zRot = angle > self.emit(QtCore.SIGNAL("zRotationChanged(int)"), angle) > self.updateGL() > > def initializeGL(self): > self.qglClearColor(self.trolltechPurple.dark()) > self.object = self.makeObject() > GL.glShadeModel(GL.GL_FLAT) > GL.glEnable(GL.GL_DEPTH_TEST) > GL.glEnable(GL.GL_CULL_FACE) > > def paintGL(self): > GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) > GL.glLoadIdentity() > GL.glTr