Hey, Your QtCore.Qt.DisplayRole is just, as it says, for displaying the value, which would be a string. You can actually store any custom amount of roles you want by using:
thisRole = QtCore.Qt.UserRole thatRole = QtCore.Qt.UserRole + 1 So that means you can easily store complex objects in one role, an id in another, etc. For advanced control over data types and editing operations, you can create a custom QitemDelegate, and use model.setItemDelegateForColumn() for a column to handle a specific type with validation. Like being able to show a spin box when editing a numeric value. On Tue, Feb 11, 2014 at 8:02 AM, olheiros <[email protected]> wrote: > > <https://lh4.googleusercontent.com/-LLu13ijoyNk/UvkiI0azMwI/AAAAAAAABXE/qPZJk8d7Jcc/s1600/Lister.png> > Thanks Marcus. Your info was very useful. > I have taken it into a point where i can store the attributes in string > format > on QTableView using the QtCore.QAbstractTableModel and it updates really > nice. > But... > > from what i have gathered untill now is that with the roles available i > can only get text in it. while > my attributes have float, boolean and tuples values. The only way i have > found to display them was to force > the value returned to str(). > > It must possible to read other data types i'm sure !! but how? > I wanted to fill my cells with spin and comboBoxes instead of the text. So > i can edited them. > > Any help is very much appretiated. > > best regards > Ricardo Viana > > > > snippet bellow: > ---------------------------------------------------------- > def data (self, index, role): > > if role == QtCore.Qt.DisplayRole: > > row = index.row() > > column = index.column() > > value = self.__lights[row][column] > > return str(value) > ------------------------------------------------------------- > > > > > > > > > On Monday, February 10, 2014 12:39:16 PM UTC, Marcus Ottosson wrote: > >> The link I gave you is about what you are attempting, but in a slightly >> more low-level way. The QTableWidget is actually a simplification of the >> QTableView and QAbstractItemModel which you will see referenced on that >> page. >> >> >> On 10 February 2014 12:05, olheiros <[email protected]> wrote: >> >>> Hi Marcus thank you for your help. >>> By dynamic i meant creating automatic instancing instead of by hand >>> writing -> newLight = Light() >>> if i want to refer to a specific light object they are all newLight. >>> Unless i can get it with __str__ or __repr__ have to investigate it aswell. >>> >>> the model view programming might be what i need to look at / learn first. >>> >>> Thank you very much >>> best >>> Ric >>> >>> >>> >>> On Monday, February 10, 2014 11:44:40 AM UTC, Marcus Ottosson wrote: >>> >>>> By "dynamic" you may be referring to having your GUI refresh whenever >>>> your scene changes. >>>> >>>> What may be simpler, at least as a start, may be to rely on a refresh >>>> on first launch of your GUI, or alternatively a refresh button within your >>>> GUI that the user could press whenever something has changed. It depends on >>>> how long you expect the GUI to be running at each run. >>>> >>>> To refresh would mean to run a loop over all lights, pm.ls(type=' >>>> VRayLightRectShape') and instantiate lightObject() from there (which >>>> by the way should have upper-case formatting - see >>>> PEP08<http://www.python.org/dev/peps/pep-0008/> >>>> ) >>>> >>>> Although I have to say, running a QTableWidget as a first excercise in >>>> OO is rather intense. You would probably have to composite lightObject >>>> within a QTableWidgetItem and override whatever method it has that deals >>>> with displaying and editing its corresponding field, either by >>>> monkey-patching or prior subclassing. >>>> >>>> Have a look here for some more hints >>>> http://qt-project.org/doc/qt-4.8/model-view-programming.html >>>> >>>> >>>> Best, >>>> Marcus >>>> >>>> >>>> On 10 February 2014 11:21, olheiros <[email protected]> wrote: >>>> >>>>> Hi all. >>>>> I am taking my first steps at object oriented, and i'm >>>>> trying to build a tool to aid me in the lighting process. >>>>> >>>>> i want to list all my Vray lights in a QTableWidget and some of its >>>>> attributes >>>>> so i can change them more easily. >>>>> >>>>> I have made a base class with all the methods of the Tool UI and its >>>>> working fine. >>>>> >>>>> I also created another class Light() with all the Light parameters and >>>>> methods. >>>>> The thing is i wanted (if possible) to instantiate as many Light() >>>>> objects as there are in the scene >>>>> so i can refer to them in the UI when changing values. But this has to >>>>> be dynamic, i mean. >>>>> >>>>> hope you see what i mean. All the examples i have seen are static >>>>> instantiation like a = light() >>>>> >>>>> in the following example i can only reach to one object. In this case >>>>> the last one to be created. >>>>> >>>>> Maybe it's my methodology that is wrong in the first place. How would >>>>> you go about this >>>>> Thanks in advance. >>>>> >>>>> Best >>>>> Ric >>>>> >>>>> ------------------------------------------------------------ >>>>> ----------------- >>>>> >>>>> import pymel.core as pm >>>>> >>>>> class lightObject(): >>>>> >>>>> def __init__(self,name): >>>>> >>>>> self.name = name >>>>> >>>>> self.color = (255,255,255) >>>>> >>>>> def __repr__(self): >>>>> >>>>> return self.name >>>>> >>>>> >>>>> >>>>> lights = pm.ls(shapes=1) >>>>> >>>>> for light in lights: >>>>> >>>>> if light.nodeType() == "VRayLightRectShape" or light.nodeType() == >>>>> "VRayLightDomeShape": >>>>> >>>>> lightNode = lightObject("%s" %light) >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> 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 [email protected]. >>>>> To view this discussion on the web visit https://groups.google.com/d/ >>>>> msgid/python_inside_maya/045c727c-ac97-4fbf-8ceb-a89d240d6f86% >>>>> 40googlegroups.com. >>>>> For more options, visit https://groups.google.com/groups/opt_out. >>>>> >>>> >>>> >>>> >>>> -- >>>> *Marcus Ottosson* >>>> [email protected] >>>> >>> -- >>> 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 [email protected]. >>> To view this discussion on the web visit https://groups.google.com/d/ >>> msgid/python_inside_maya/96c133e4-5cce-4d78-93d2- >>> 3854dad6c7ca%40googlegroups.com. >>> >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >> >> >> >> -- >> *Marcus Ottosson* >> [email protected] >> > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/131b9998-c464-43be-9d49-ad28de22bc8e%40googlegroups.com > . > > For more options, visit https://groups.google.com/groups/opt_out. > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0d8SAmhGqb58r-hmmKap0PPuUNuQjn-NMypSpfkqYPig%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
