Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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>
Solved! Go to Solution.