3ds Max 2017: Is there a way to get the main QT window?

3ds Max 2017: Is there a way to get the main QT window?

Anonymous
Not applicable
3,115 Views
8 Replies
Message 1 of 9

3ds Max 2017: Is there a way to get the main QT window?

Anonymous
Not applicable

Hi everyone,

 

In 3ds Max 2018, I can retrieve the QTMainWindow with

 

GetCOREInterface()->GetQmaxMainWindow()

So far I have been unable to find any way of retrieving the Qt main window in 3ds max 2017. Is there any way of doing this?

 

Thank you!

0 Likes
3,116 Views
8 Replies
Replies (8)
Message 2 of 9

malcomarmstrong
Advocate
Advocate

I remember that there was an update (service pack?) that added some main window attachment. I was looking through some old notes and found:

MaxPlus.AttachQWidgetToMax(aWin )

Where aWin is a QtWidget.

 

Also:

MaxPlus.Win32.GetMAXHWnd()

So, it may be possible to parent it, though I am unsure of the sorting order.

Is there a particular reason you need to use 2017? If possible, avoid it and move to 2019 where the Python is better. I am converting old scripts and the process, while not perfect, is much better than previous implementations.

 

Hope this helps

0 Likes
Message 3 of 9

morten_bohne
Advocate
Advocate

in python you can do this (tested in max 2017 19.0HF commercial)

import MaxPlus
print(MaxPlus.GetQMaxWindow())
<PySide.QtGui.QWidget object at 0x000000007E727DC8>

or you could do it through PySide like this:

from PySide import QtGui
def get_main_windows():
    """
    Finds main window/QWidgets
    :rtype: list
    """

    # get all top level windows
    top_level_windows = QtGui.QApplication.topLevelWidgets()

    # from this list, find the main application window.
    no_parent_windows = list()
    for w in top_level_windows:
        if (
                type(w) == QtGui.QWidget and
                w.parentWidget() is None):
            no_parent_windows.append(w)
    return no_parent_windows
print(get_main_windows()[0])
<PySide.QtGui.QWidget object at 0x000000007E7278C8>
0 Likes
Message 4 of 9

malcomarmstrong
Advocate
Advocate

Well, if it works, it works but I do not go anywhere near 2017 as I found it to be a halfway house between python implementations. Now that PySide2 has been "agreed" on, thats what I will use going foprward.

 

2018 and 2019 are far better. Still needs better documentation for MaxPlus and pymxs, but it is improving. 

 

regards

0 Likes
Message 5 of 9

morten_bohne
Advocate
Advocate

I can only agree on that. Unfortunately the studio i work at uses 2017, and updating isn't an option right now. I really hope autodesk will give python in all their packages a big overhaul when (if) they move to py3 in 2020.

 

(haven't heard if they actually update in 2020, but python2 will not be maintained after january 1, 2020 and vfx platform sets the move to python3 to CY2020)

 

http://www.vfxplatform.com

https://pythonclock.org

0 Likes
Message 6 of 9

Anonymous
Not applicable

I should have mentioned that I am trying to do this in C++.

0 Likes
Message 7 of 9

malcomarmstrong
Advocate
Advocate

Ah, then no. Sorry. Gonna have a poke around in the sdk, see what turns up. Been meaning to do some c++ stuff, but always found setting up the dev environment to be a ballache. I was going to go via the UE4 engine as they seem to have an easy to follow way of getting the right versions and ide/dev environment.

Its probably not that hard, but in my experience you need to know which version goes with which env and other mystical setup passages of doom before you can scrawl a "Hello World!" program, compiled on the bones of your code.

 

Well, maybe not that tragic.

 

But still, c++ still tempts me. Smiley Very Happy

Message 8 of 9

morten_bohne
Advocate
Advocate

hey, sorry to highjack the subject, but I just noticed that using the way i posted for getting main window through PySide, causes some of max's ui-elements to break (if I create a modal message-box in the main-window I get through PySide, the command-panel breaks in max 2017 19.0HF commercial). Doing the same after getting it through MaxPlus seems to work.

0 Likes
Message 9 of 9

Anonymous
Not applicable

@Anonymous wrote:

I should have mentioned that I am trying to do this in C++.


The only way I was able to do it was to call a Python function that returns the HWND of the main Qt window for Max's main QWidget, and then loop through each QWidget in the QApp until I find the matching WinID.  That's the proper QWidget to parent everything.  More annoying is that you have to execute MaxScript to execute Python to get the HWND back, then loop and parent.

 

It's exactly what Max's is doing in Python, just in C++.  From MaxPlusExtended.py:

def GetQMaxWindow():
    '''Get the 3ds Max internal QWidget window that could be used for parenting your QWidget.'''

    if _gCachedQMaxWindow:
        return _gCachedQMaxWindow

    maxHwnd = MaxPlus.QtHelpers.GetQMaxWindowWinId()
    for w in QtGui.QApplication.allWidgets():
        if _PyCObjectToInt(w.effectiveWinId()) == maxHwnd:
            globals()['_gCachedQMaxWindow'] = w
            break
    return _gCachedQMaxWindow

For whatever reason, I couldn't call MaxPlus.QtHelpers.GetQMaxWindowWinId() directly from C++, and had to wrap it in another function first.

0 Likes