DzUserDrawStyle - Get the pixmap into a comboBox?

bigD3dbigD3d Posts: 75

Hello all,

I just posted part one of this on how to get the list of user draw styles from the viewport manager and then shortly after, figured that out.

Now i'd like to know if anyone knows how to get the icon/pixmap for those into a combo box in a script?

Reference: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/userdrawstyle_dz

I am getting the getDescription() text into my combo box (attachment 1) but am curious if I can make my script look like the viewport screen (attachment two).

Code to get the description is:

var oViewportMgr = App.getInterface().getViewportMgr();

var numUserDrawStyles = oViewportMgr.getNumUserDrawStyles();

for(i=0; i < numUserDrawStyles ; i++) {

drawStyleTypeComboBox.addItem(oViewportMgr.getUserDrawStyle(i).getDescription());

}

Any help is greatly accpreciated!

Script ComboBox.jpg
424 x 405 - 24K
Draw Styles.jpg
310 x 323 - 41K
Post edited by bigD3d on

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,842

    Would you perhaps get the drawstyle action from ActionMgr, then the icon from the action?

  • bigD3dbigD3d Posts: 75
    edited May 2021

    Thanks for the reply Richard.

    I probably should have mentioned in the original post - I believe I can get the pixmap of the icon of the draw style from the same DzUserDrawStyle object, but haven't verified it. 

    ... oViewportMgr.getUserDrawStyle(i).getPixmap();

     

    I am *assuming* this will return the little icon that is in the dropdown on the viewport next to the drawstyle name/description. When I change my code to use .getPixmap() my drop down list has "object [Object]". I have yet to try to view the icon to see that it is really it.

    The documentation has this for the object description:

    Any draw styles which should be available to the user for selecting need to be derived from this class.
    Subclasses must implement the getPixmap() to return the icon that will be displayed in the viewport drop-down list,
    and getDescription() to return the text that accompanies the icon.

     

    So assuming that is correct, the real question is - is there a combobox object available in scripting that can show the icon and description together? I've been assuming (again) that every UI object in Daz Studio can be created from a script, but I don't see anything yet that would do a combobox with an icon/image and text.

    Is there another kind of UI object instead of a combobox I should be looking for?

    thanks again

    Post edited by Richard Haseltine on
  • Richard HaseltineRichard Haseltine Posts: 100,842

    If you see object [Object] that usually means that the wrong item has been passed - possibly the whole object when only one of its members is required. If you pass the wrong type of object entirely that usually geenrates a complaint that the function doesn't match any of the overloaded signatures available.

  • bigD3dbigD3d Posts: 75

    When I look at the documentation for DzComboBox ( http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/combobox_dz ) I see it's a wrapper for QComboBox. The QComboBox object appears to support icons and text in the list item, but I can't create an object of that type, like say I can for QImage. Any idea how to access/use the QComboBox via script?

    Alternatively, I see DzListView can take DzListViewItems, and the DzListViewItems can have a pixmap and text. But I haven't yet figured out how to make these object show in my dialog correctly (and not sure if they are the appropriate control either...).

    thanks

     

  • DafaDafa Posts: 97

    bigD3d said:

    When I look at the documentation for DzComboBox ( http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/combobox_dz ) I see it's a wrapper for QComboBox. The QComboBox object appears to support icons and text in the list item, but I can't create an object of that type, like say I can for QImage. Any idea how to access/use the QComboBox via script?

    Alternatively, I see DzListView can take DzListViewItems, and the DzListViewItems can have a pixmap and text. But I haven't yet figured out how to make these object show in my dialog correctly (and not sure if they are the appropriate control either...).

    thanks

    I don't think that is possible for DAZ Script. I believe the only way to access QComboBox is by utilizing the Daz SDK.

    You could, however, design the entire widget/dialog using the QtDesigner app (designer.exe) where DAZ is installed. You can then create a DzUILoader object, load it, and show it.

    DzUILoader

    DzWidget

    var oUILoader = new DzUiLoader();var oWidget = oUILoader.load("E:/test.ui"); // Returns a DzWidget.oWidget.show(); // Reveal the DzWidget.sleep(5000); // Show for 5 seconds.

    You could also add a pixmap loading from an image file with a transparent background. You'd just have to resize it, I believe. I haven't really worked with Pixmap so good luck :)

  • bigD3dbigD3d Posts: 75
    edited May 2021

    Dafa said:

    bigD3d said:

    When I look at the documentation for DzComboBox ( http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/combobox_dz ) I see it's a wrapper for QComboBox. The QComboBox object appears to support icons and text in the list item, but I can't create an object of that type, like say I can for QImage. Any idea how to access/use the QComboBox via script?

    Alternatively, I see DzListView can take DzListViewItems, and the DzListViewItems can have a pixmap and text. But I haven't yet figured out how to make these object show in my dialog correctly (and not sure if they are the appropriate control either...).

    thanks

    I don't think that is possible for DAZ Script. I believe the only way to access QComboBox is by utilizing the Daz SDK.

    You could, however, design the entire widget/dialog using the QtDesigner app (designer.exe) where DAZ is installed. You can then create a DzUILoader object, load it, and show it.

    DzUILoader

    DzWidget

    var oUILoader = new DzUiLoader();var oWidget = oUILoader.load("E:/test.ui"); // Returns a DzWidget.oWidget.show(); // Reveal the DzWidget.sleep(5000); // Show for 5 seconds.

    You could also add a pixmap loading from an image file with a transparent background. You'd just have to resize it, I believe. I haven't really worked with Pixmap so good luck :)

     

    Dafa,

    thanks very much for this. I have used the QTDesigner as a starting point to layout the basics of my dialogs and puchased Dialog Design ( https://www.daz3d.com/dialog-design ) to have most of the controls i've used converted into their Dzxxx objects in script. I vaguely recall the DzUiLoader when researching on how to get started in scripting and don't recall why I didn't use/try it - and since completely forgot about it. 

    I have a couple of questions on this too:

    * Once you have oWidget loaded, is that the actual dialog object, with the QComboBox as a child object?

    * If yes, how do you access the QComboBox object for scripting? For instance to grab which selection the user picked, or add/remove selection choices dynamically.

    * I see in DzUiLoader reference a "createWidget()" method which references a QObject in the method signature. Do you use it to bypass loading the whole dialog and create the QComboBox from "within" the objects of the *.ui file?

    I hope those questions make sense. I'll definately mess around with this after work tonight.

    thanks again

     

    Post edited by bigD3d on
  • DafaDafa Posts: 97
    edited May 2021

    bigD3d said:

    Dafa,

    thanks very much for this. I have used the QTDesigner as a starting point to layout the basics of my dialogs and puchased Dialog Design ( https://www.daz3d.com/dialog-design ) to have most of the controls i've used converted into their Dzxxx objects in script. I vaguely recall the DzUiLoader when researching on how to get started in scripting and don't recall why I didn't use/try it - and since completely forgot about it. 

    I have a couple of questions on this too:

    * Once you have oWidget loaded, is that the actual dialog object, with the QComboBox as a child object?

    Yes, it returns a DzWidget with QComboBox instead of DzComboBox. 

    * If yes, how do you access the QComboBox object for scripting? For instance to grab which selection the user picked, or add/remove selection choices dynamically.

    This is where I think the UILoader option comes to an end. I was curious my self. So, you can access all objects of the parented DzWidget by doing this:

    var oChildren = oWidget.getChildrenOfWidget(); // Returns an array of Objects

    You could then do a for loop to find the QComboBox or findChildOfWidget(). Unfortunately, because you wanted a QComboBox, it is unclear what properties or methods you can access. For example, in the QT documentation, you should be able to call count(), nope. So then I thought maybe it can be called by some of the methods available in the Daz Documentation, like getWidget(), nope. You'll get a TypeError stating they're not functions. However, you can get properties from the QComboBox which is weird. It's very confusing. Also, the objects do not inherit DzWidget.

    var oChildren = oWidget.getChildrenOfWidget();for (i = 0; i < oChildren.length; i++) {    // I'm looking for QComboBox for my case since I only have a empty dialog, a combo box, and a combo box item.	if (oChildren[i].inherits("QComboBox")) {        print(oChildren[i].count()); // TypeError: Not a function (Qt)        print(oChildren[i].getWidget()); // TypeError: Not a function. (Dz)        print(oChildren[i].count); // Works.        print(oChildren[i].maxCount); // Works.        print(oChildren[i].inherits("DzWidget")); // Returns false.    }}

    * I see in DzUiLoader reference a "createWidget()" method which references a QObject in the method signature. Do you use it to bypass loading the whole dialog and create the QComboBox from "within" the objects of the *.ui file?

    At this point, I'm not even sure. createWidget() is documented to return a DzWidget but instead returns a QWidget. I do know that createWidget() isn't used to load any .ui files.

    I hope those questions make sense. I'll definately mess around with this after work tonight.

    thanks again

    Sorry I couldn't be much help.

    Post edited by Dafa on
  • bigD3dbigD3d Posts: 75

    Dafa said:

    bigD3d said:

    Dafa,

    thanks very much for this. I have used the QTDesigner as a starting point to layout the basics of my dialogs and puchased Dialog Design ( https://www.daz3d.com/dialog-design ) to have most of the controls i've used converted into their Dzxxx objects in script. I vaguely recall the DzUiLoader when researching on how to get started in scripting and don't recall why I didn't use/try it - and since completely forgot about it. 

    I have a couple of questions on this too:

    * Once you have oWidget loaded, is that the actual dialog object, with the QComboBox as a child object?

    Yes, it returns a DzWidget with QComboBox instead of DzComboBox. 

    * If yes, how do you access the QComboBox object for scripting? For instance to grab which selection the user picked, or add/remove selection choices dynamically.

    This is where I think the UILoader option comes to an end. I was curious my self. So, you can access all objects of the parented DzWidget by doing this:

    var oChildren = oWidget.getChildrenOfWidget(); // Returns an array of Objects

    You could then do a for loop to find the QComboBox or findChildOfWidget(). Unfortunately, because you wanted a QComboBox, it is unclear what properties or methods you can access. For example, in the QT documentation, you should be able to call count(), nope. So then I thought maybe it can be called by some of the methods available in the Daz Documentation, like getWidget(), nope. You'll get a TypeError stating they're not functions. However, you can get properties from the QComboBox which is weird. It's very confusing. Also, the objects do not inherit DzWidget.

    var oChildren = oWidget.getChildrenOfWidget();for (i = 0; i < oChildren.length; i++) {    // I'm looking for QComboBox for my case since I only have a empty dialog, a combo box, and a combo box item.	if (oChildren[i].inherits("QComboBox")) {        print(oChildren[i].count()); // TypeError: Not a function (Qt)        print(oChildren[i].getWidget()); // TypeError: Not a function. (Dz)        print(oChildren[i].count); // Works.        print(oChildren[i].maxCount); // Works.        print(oChildren[i].inherits("DzWidget")); // Returns false.    }}

    * I see in DzUiLoader reference a "createWidget()" method which references a QObject in the method signature. Do you use it to bypass loading the whole dialog and create the QComboBox from "within" the objects of the *.ui file?

    At this point, I'm not even sure. createWidget() is documented to return a DzWidget but instead returns a QWidget. I do know that createWidget() isn't used to load any .ui files.

    I hope those questions make sense. I'll definately mess around with this after work tonight.

    thanks again

    Sorry I couldn't be much help.

    I'll see what I can do messing around with all this tonight. It's really frustrating that the Dz wrapper doesn't fully support the underlying QComboBox. This seems like it would be a very nice option to set some icons and improve people's script projects, especially for those going to be sold on the site.

    But it's starting to lean towards having no icons in my DzComboBox and just use the draw style descriptions. I did make a DzListView with DzListViewItems which allowed the icon to be in a column, but that takes up alot of room on the dialog.

    thanks again for all the info.

  • Richard HaseltineRichard Haseltine Posts: 100,842

    Rob suggests using a DzPushButton in the dialogue, then when it signals it's been pushed show a DzPopupMenu which can show the Pixmaps as well as the label

  • Richard, in your opinion, what is the discriminant that determines which questions a dev will take the time to answer, and which ones he will ignore?

  • Richard HaseltineRichard Haseltine Posts: 100,842

    TheMysteryIsThePoint said:

    Richard, in your opinion, what is the discriminant that determines which questions a dev will take the time to answer, and which ones he will ignore?

    I would imagine there are many factors, from available time to complexity of the question, but I'm sure the way in which the question is asked is a factor.

  • bigD3dbigD3d Posts: 75

    Richard Haseltine said:

    Rob suggests using a DzPushButton in the dialogue, then when it signals it's been pushed show a DzPopupMenu which can show the Pixmaps as well as the label

    Richard, thanks for this. I will definately try this approach. 

  • Richard HaseltineRichard Haseltine Posts: 100,842

    bigD3d said:

    Richard Haseltine said:

    Rob suggests using a DzPushButton in the dialogue, then when it signals it's been pushed show a DzPopupMenu which can show the Pixmaps as well as the label

    Richard, thanks for this. I will definately try this approach. 

    Apparently you have to insert one of the elements into the menu item, then change the other - you can't just insert both pixmap and text. This is an issue that is being addressed, as is the documentation of DzPushButton.

  • jag11jag11 Posts: 885

    HTH

    var viewportMgr = App.getInterface().getViewportMgr();var dialog = new DzDialog();var drawStylesButton = new DzPushButton(dialog);var drawStylesPopup = new DzPopupMenu(dialog);var drawStyle = null;var drawStylePixmap = null;var numUserDrawStyles = viewportMgr.getNumUserDrawStyles();dialog.width = 520;dialog.height = dialog.width / 1.7;drawStylesButton.width = 32;drawStylesPopup.x = 0;drawStylesPopup.y = 30;for (var i = 0; i &lt; numUserDrawStyles; i++) {    drawStyle = viewportMgr.getUserDrawStyle(i);    drawStylePixmap = drawStyle.getPixmap();    drawStylesPopup["insertItem(QPixmap,int)"](drawStylePixmap, i);    drawStylesPopup["changeItem(int,QString)"](i, drawStyle.getDescription());}drawStylesPopup.activated.connect(function (id) {    drawStylesButton.pixmap = drawStylesPopup.pixmap(id);});drawStylesButton.pixmap = drawStylesPopup.pixmap(0);drawStylesButton.clicked.connect(function () {    var p = dialog.mapToGlobal(new Point(drawStylesButton.x, drawStylesButton.height));    drawStylesPopup.popup(p, 0);});dialog.exec();
Sign In or Register to comment.