0

Where are all the PYQT window icons? Does shotgun disable them?

Hi, I was wondering when with a PYQT window run through shotgun, when I use the code to get a window icon to show, nothing happens

iconName = str( os.path.dirname( os.path.abspath(__file__) ) ) + "\\favicon.ico"
self.setWindowIcon( QtGui.QIcon(iconName) )

This code works when I use my other windows, do do have any ideas on how to make this work?

Cheers!

 

6 comments

  • 0
    Avatar
    Alan Dann

    Hi Nick,

    What is self in self.setWindowIcon( QtGui.QIcon(iconName) ) - is this the widget you are creating in your app?  Are you then using engine.show_dialog()/engine.show_modal() to show the window?

    Or is this your own Window created completely independently of the Toolkit window management?

    Thanks

    Alan

     

  • 0
    Avatar
    Hughes- Nick

    Thanks for replying! Our email is down at work so didn't realize you had responded.

    We are using the

    app.engine.show_dialog("XLS Data Gatherer", app, AppDialog, app)

    from an __init__.py

    This "XLS Data Gatherer" is then referencing a pyqt template build from designer and then converted using pyside-uic.exe. So self from the self.setWindowIcon( QtGui.QIcon(iconName) ) is the app window

    or object 

    <tank.platform.qt.tankqdialog.__AppDialog_TkWidgetWrapper__ object at 0x0000000004D4DE08>

     

    Cheers

    Nick

  • 0
    Avatar
    Alan Dann

    Hi Nick,

    That's what I thought/hoped you were doing :)

    The show_dialog() method actually returns the newly created AppDialog widget which is a child of a Toolkit dialog (it's actually nested a few layers down!).  There are two reasons we don't just create a dialog directly from your class:

    • Firstly, by being in control of the top level window, we can add common UI elements to all Toolkit dialogs such as the banner and access to the settings etc.  We also have some other ideas for this which would help improve workflow between apps in the future...
    • Secondly (and most importantly), by taking control of the Window creation and management, we can ensure it works in every engine correctly - something which isn't always an easy thing to do!

    When you are setting the icon, you are actually setting it on a child widget of the window which will have no effect!

    What you need to do then is find the dialog window parent and set the icon on that.  There is a Qt method: QWidget.window() but we've seen instability when using this in Nuke so the following python function can be used instead to find the dialog window which you can then set the icon on:

     

    def get_widget_dialog(self, widget):
    """
        Get the widgets dialog parent.
    """
    current_widget = widget
    while current_widget:
    if isinstance(current_widget, QtGui.QDialog):
    return current_widget
    current_widget = current_widget.parentWidget()
    return None

     

    Let me know if that works for you?

    Thanks

    Alan

  • 0
    Avatar
    Hughes- Nick

    Hi Alan! Sorry for the late reply again, but cheers for getting back to me!

    What do I pass to this function? as 'widget'? I've tried a few things and all seem to fail

     

        from tank.platform.qt import QtCore, QtGui
        from .ui.exterminator_ui import Ui_Dialog
    class AppDialog(QtGui.QWidget): def __init__(self, app): QtGui.QWidget.__init__(self) self._app = app

    self.ui = Ui_Dialog() self.ui.setupUi(self)

    cheers

  • 0
    Avatar
    Alan Dann

    Hi Nick, 

    Pass it the widget returned by the show_dialog() function e.g.:

    widget = self._app.engine.show_dialog(...)
    dialog = self.get_widget_dialog(widget)

    Unfortunately, you can't do this from within your QWidget class as it's constructed before the parent dialog!

    Does that work for you?

    Thanks

    Alan

     

  • 0
    Avatar
    Philip Scadding

    I tested this on behalf of Nick, and yeah that works fine. Thank you

Please sign in to leave a comment.