Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

UI widget will not resize its layouts using QUiLoader

UI widget will not resize its layouts using QUiLoader

mark.henne
Explorer Explorer
1,269 Views
2 Replies
Message 1 of 3

UI widget will not resize its layouts using QUiLoader

mark.henne
Explorer
Explorer

I have a .ui file created with Qt Designer that adjust its layouts properly in Designer when the window is resized.  When I import that into Maya 2020 (or 2018) the window displays properly, but the layouts will not adjust when it is resized.  Attached is a very simple case that shows the problem, a QWidget (grid layout) with a child QVBoxLayout containing a QPushButton.

 

Thanks for any help.

 

Mark

 

test_ui.py

 

from PySide2 import QtCore
from PySide2 import QtWidgets
from PySide2 import QtUiTools
from shiboken2 import wrapInstance

import maya.OpenMayaUI as omui
import pymel.core as pm
import os

# .ui file is same folder as .py file
absFilePath = os.path.abspath(__file__)
path, filename = os.path.split(absFilePath)
uiFile = os.path.join(path, 'test_ui.ui')

def getMayaWindow():
    windowPtr = omui.MQtUtil.mainWindow()
    return wrapInstance(long(windowPtr), QtWidgets.QWidget)

class TestUI(QtWidgets.QDialog):
    
    def __init__(self, parent=getMayaWindow()):
        super(TestUI, self).__init__(parent)
        
        uiFileQt = QtCore.QFile(uiFile)
        uiFileQt.open(QtCore.QFile.ReadOnly)
        
        loader = QtUiTools.QUiLoader()
        self.ui = loader.load(uiFileQt, parentWidget=self)
        uiFileQt.close()

        self.show()

 

test_ui.ui

 

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Form</class>
 <widget class="QWidget" name="Form">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>394</width>
    <height>222</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <layout class="QGridLayout" name="gridLayout">
   <item row="0" column="0">
    <layout class="QVBoxLayout" name="verticalLayout">
     <item>
      <widget class="QPushButton" name="pushButton">
       <property name="sizePolicy">
        <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
         <horstretch>0</horstretch>
         <verstretch>0</verstretch>
        </sizepolicy>
       </property>
       <property name="text">
        <string>PushButton</string>
       </property>
      </widget>
     </item>
    </layout>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

 

 

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

m.lokeshkumar2008
Explorer
Explorer
Accepted solution
class TestUI(QtWidgets.QDialog):
    
    def __init__(self, parent=getMayaWindow()):
        super(TestUI, self).__init__(parent)
        
        uiFileQt = QtCore.QFile(uiFile)
        uiFileQt.open(QtCore.QFile.ReadOnly)
        
        loader = QtUiTools.QUiLoader()
        self.ui = loader.load(uiFileQt, parentWidget=self)
        uiFileQt.close()
        
        # from here 
        self.ui.setParent(self)
        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.ui)
        self.resize(self.ui.size())
        self.setLayout(layout)
        # Till here

        self.show()

 

Hi @mark.henne 

Try above code in between from here and till here comments, it might help you dude.

Message 3 of 3

mark.henne
Explorer
Explorer

Sweet!  That works perfectly, @m.lokeshkumar2008 

 

Thanks a ton!

 

Mark

0 Likes