How to size and center my GUI.

235 views
Skip to first unread message

jettam

unread,
Oct 18, 2017, 7:18:00 PM10/18/17
to Python Programming for Autodesk Maya
Using pyside2uic I converted my QtDesigner.  It's super simple for my testing Just one pushbutton.

I can get it to launch in Maya. Great! But its small and not centered to the maya window.  I tried adding some code at the bottom that is suppose to scale it to 350x375 and center it. But its not working. 



# Loading a Qt Designer UI file and editing the loaded widget

import os
from PySide2 import QtWidgets, QtCore, QtUiTools, QtGui
from shiboken2 import wrapInstance
import maya.cmds as mc
import maya.OpenMayaUI as omui

def getMayaWindow():
 
''' pointer to the maya main window '''
 ptr
= omui.MQtUtil.mainWindow()
 
if ptr:
 
return wrapInstance(long(ptr), QtWidgets.QMainWindow)

def run():
 
''' builds our UI '''
 
global win
 win
= GeometryGenerator(parent=getMayaWindow())
 
#win.show()

class GeometryGenerator(QtWidgets.QDialog):
 
 
def __init__(self,parent=None):
 
super(GeometryGenerator,self).__init__(parent)


 
# From Pysideuic compiler

 
self.gridLayout = QtWidgets.QGridLayout()
 
self.pushButton_A = QtWidgets.QPushButton()
 
self.gridLayout.addWidget(self.pushButton_A, 0, 0, 1, 1)

 
self.setWindowTitle(" WIN CONTROLLED IN PYTHON ")
 
self.setLayout(self.gridLayout)
 
self.show()




 
# maya win dimensions
 parentWidth
= parent.width()
 parentHeight
= parent.height()

 guiWidth
= 350
 guiHeight
= 375

 posX
= parentWidth * 0.5 - (guiWidth * 0.5) + parent.x()
 posY
= parentHeight * 0.5 - (guiHeight * 0.5) + parent.y()

 
self.ui.setGeometry(posX, posY, guiWidth, guiHeight)




      


Justin Israel

unread,
Oct 18, 2017, 8:46:43 PM10/18/17
to python_in...@googlegroups.com
On Thu, Oct 19, 2017 at 12:18 PM jettam <justin...@gmail.com> wrote:
Using pyside2uic I converted my QtDesigner.  It's super simple for my testing Just one pushbutton.

I can get it to launch in Maya. Great! But its small and not centered to the maya window.  I tried adding some code at the bottom that is suppose to scale it to 350x375 and center it. But its not working. 

I can't tell from your code, because its incomplete, but it looks like you should be calling the size operation on "self" instead of "self.ui". If "self.ui" is constrained to the main dialog then the resize and move wont do anything. You want to resize and move your top level dialog.
 
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c7488c6d-4316-4b62-849c-e0cff6acae20%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Simon Anderson

unread,
Oct 18, 2017, 9:50:32 PM10/18/17
to Python Programming for Autodesk Maya
This usually works for me when setting a size of a dialog.

self.resize(QSize(500,300))

Try and call this inside the init method, before you call show().
Reply all
Reply to author
Forward
0 new messages