Custom ui with QComboBox - addItem

Custom ui with QComboBox - addItem

Christian_Garimberti
Advisor Advisor
941 Views
2 Replies
Message 1 of 3

Custom ui with QComboBox - addItem

Christian_Garimberti
Advisor
Advisor

Hi guys,

i'm trying to crate a small dialog to configure my project, and i need to use some ComboBox, but i can add values to them...

I need to do this in the Script Editor, the code should be inside the Vpb file.

I tried with this code, but i got an error using the addItem

 

xml = """<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
    <class>vrFimConfigurationPlugin</class>
    <widget class="QWidget" name="vrFimConfigurationPluginGUI">
        <property name="geometry">
            <rect>
                <x>0</x>
                <y>0</y>
                <width>300</width>
                <height>300</height>
            </rect>
        </property>
        <property name="windowTitle">
            <string>Configurazione</string>
        </property>
        
        <layout class="QVBoxLayout" name="FimCfgDialogLay">

            <item>
                <widget class="QLabel" name="Title">
                    <property name="text">
                        <string>My Combo Title</string>
                    </property>
                </widget>
            </item>
            <item>
                <widget class="QComboBox" name="_MyCombo">
                    
                </widget>
            </item>
            
        </layout>
        
    </widget>
    <resources/>
    <connections/>
</ui>
"""

MyDialog = vrWidget(xml)
MyDialog.setToolWindow(True)

myCombo = findQObject(MyDialog.getQObject(), "_MyCombo")
myCombo.addItem("My Value")

 

 

Where i am wrong? Or i have to change approach?

 

Best

Chris

Christian Garimberti
Technical Manager and Visualization Enthusiast
Qs Informatica S.r.l. | Qs Infor S.r.l. | My Website
Facebook | Instagram | Youtube | LinkedIn

EESignature

0 Likes
Accepted solutions (1)
942 Views
2 Replies
Replies (2)
Message 2 of 3

michael.horschELP2G
Autodesk
Autodesk
Accepted solution

findQObject returns a vrQObject which doesn't have an addItem()-Method, so this is expected.

 

I'm not familiar enough with the scripting API, but if you know the options when the script is started, you could add them to the ComboBox in the ui-xml dynamically:

xml = """<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
    <class>vrFimConfigurationPlugin</class>
    <widget class="QWidget" name="vrFimConfigurationPluginGUI">
        <property name="geometry">
            <rect>
                <x>0</x>
                <y>0</y>
                <width>300</width>
                <height>300</height>
            </rect>
        </property>
        <property name="windowTitle">
            <string>Configurazione</string>
        </property>
        
        <layout class="QVBoxLayout" name="FimCfgDialogLay">

            <item>
                <widget class="QLabel" name="Title">
                    <property name="text">
                        <string>My Combo Title</string>
                    </property>
                </widget>
            </item>
            <item>
                <widget class="QComboBox" name="_MyCombo">
                """
for i in range(10):
    xml+="""<item>
    <property name="text">
     <string>Element"""+str(i)+"""</string>
    </property>
   </item>"""
   
someValue=true
if someValue is true:
    xml+="""<item>
    <property name="text">
     <string>OptionWhensomeValueIsTrue</string>
    </property>
   </item>"""
    
               
xml+="""
                </widget>
            </item>
            
        </layout>
        
    </widget>
    <resources/>
    <connections/>
</ui>
"""

 

0 Likes
Message 3 of 3

Christian_Garimberti
Advisor
Advisor

Thank You @michael.horschELP2G ! This is what i need! I didn't thought to "edit" the xml code at runtime!

i searched for the "addItem" because if i use a comboBox in a scriptPlugin it works. But effectively i was working on a different object.

 

Then i chose another way for my project, cause i would like to use my project also with the streaming app, so i used an HTML frontplate.

But for other application i'll keep your solution in mind.

 

Thank You

Chris

Christian Garimberti
Technical Manager and Visualization Enthusiast
Qs Informatica S.r.l. | Qs Infor S.r.l. | My Website
Facebook | Instagram | Youtube | LinkedIn

EESignature

0 Likes