I tried many things to get this working yesterday. Today I did some more research and came up with this topic: cgsociety: creating a floating button inside the viewport
In the case of a broken link, this is one of the answers:
You can use geometry, but there are some problems with running commands based on selection and undo queue. If you want to go the route, I would suggest looking at zooHud and zooTriggers (part of zooToolbox)
If you want the actual GUI control to be selected for viewing, mel only offers hudslider, hudbutton and headUpMessage.
You can also use PyQt and parent in your own widgets / layouts or whatever you want to use something like this:
import maya.OpenMayaUI as apiUI import sip from PyQt4 import QtGui view = apiUI.M3dView() apiUI.M3dView.getM3dViewFromModelPanel('modelPanel4', view) viewWidget = sip.wrapinstance(long(view.widget()), QtCore.QObject) global myBtn myBtn = QtGui.QPushButton(viewWidget) myBtn.setText('testing!') myBtn.move(100, 100)
You can do whatever the full Qt widget can do, so it is extremely flexible. but this will require installing PyQt, it may be a barrier depending on the distribution of your tools.
I made a mixture of this answer and your code:
from PySide import QtCore, QtGui from maya import OpenMayaUI as omui from shiboken import wrapInstance class CustomQWidget(QtGui.QWidget): def __init__(self, *args, **kwargs): QtGui.QWidget.__init__(self, *args, **kwargs) mainLayout = QtGui.QVBoxLayout(self) closeButton = QtGui.QPushButton('CLOSE') closeButton.setFixedSize(80, 40) closeButton.clicked.connect(self.deleteLater) helloButton = QtGui.QPushButton('HELLO') helloButton.setFixedSize(80, 40) helloButton.clicked.connect(self.printHello)
One of the problems is that the widget's background is clogged: 
If anyone knows why and how to fix it, I will be happy to edit my answer. In addition, when you run this script from a Mayan script, the widget editor follows the panel when it changes.